JDK-4744405 : RFE: lookupPrintServices() to refresh the printers list dynamically
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0,1.4.1,1.4.2,5.0u6,5.0u14
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    linux,solaris_8,windows_2000,windows_xp linux,solaris_8,windows_2000,windows_xp
  • CPU: x86,sparc
  • Submitted: 2002-09-10
  • Updated: 2016-04-07
  • Resolved: 2005-04-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other JDK 6
5.0u18-revFixed 5.0u19Fixed 6 b33Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
*This also happened on Windows platform.

java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)

When invoke method lookupPrintServices() on class PrinterJob or PrintServiceLookup, the printers list can not refreshed when adding or deleting printers dynamically.

Steps to follow to reproduce the problem:
 1. Compile and run the included test case
 2. The print dialog shows up and avaible printers information is printed out on screen. Click "cancel" to dismiss the dialog. The test case is pending.
 3. Use Printer Selector Tool to add a new printer into selected printers list and save changes.
 4. Back to the terminal that run the test case an click "enter" button to continue. Then a new thread will be created to invoke the lookupPrintServices() and pop up the print dialog again.
 5. The screen output shows that invoking lookupPrintServices() doesn't reflect the newly added printer information, neither does the print dialog.

//-------- source code begin-----------//
import java.awt.print.*;
import javax.print.*;

public class MTPrinterTest extends Thread {
    public static void main(String[] args) {
        MTPrinterTest t1 = new MTPrinterTest();
        t1.start();
        
        try {
            System.in.read();
        } catch (Exception e){}
        
        MTPrinterTest t2 = new MTPrinterTest();
        t2.start();
    }
    public void run() {
        PrinterJob printerJob;
        PrintService[] printServices;

        printerJob = PrinterJob.getPrinterJob();
        printServices = printerJob.lookupPrintServices();
        System.out.println("Number of servies found: " + printServices.length);
        for (int i =0; i< printServices.length; i++)
            System.out.println("--> Available Printer " + i + ": " + printServices[i]);
        printerJob.printDialog();    
    }  
}
//-------- source code end ----------//

Comments
EVALUATION Since this report cites Solaris then I will address that O/S first: This was a deliberate and conscious implementation decision, forced on us by the lack of any printer enumeration API on Solaris. So it takes an enormous amount of time (seconds!) to get the list of printers on Solaris, and on many networks there are hundreds of printers. There would also need to be a way to identify new ones quickly. So we are unlikely to do anything about this until such time as the O/S provides the necessary services with suitable performance characteristics. We took into account the rarity of new print services being added during the execution of a program. The other implementations were made consistent with this, although its generally faster to identify new print services on windows, and linux tends to have fewer printers, which also make it quicker. Its certainly more possible to do this on windows, but again the extreme rarity and easy solution (restart the app) meant it was not a priority. ###@###.### 2002-09-10 ============================ If implemented this also needs to track changes to default values of attributes such as the default page size for printer, and also the default printer for a system, as requested in RFE 6182986 ###@###.### 2005-1-06 18:36:32 GMT Fixed by using a polling method on Solaris and Linux (ie Unix) with an option to use another method by refreshing it everytime lookupPrintServices is called. This is set using an internal (non-public) system property. In Windows, refresh is done everytime we get a printer change notification. ###@###.### 2005-03-28 22:50:23 GMT ###@###.### 2005-03-29 17:16:05 GMT
28-03-2005

WORK AROUND Exit the current running application and run it again, then the printers list get refreshed. Seems the running JVM can not get updated printer information. If the application is a desktop office suite, restarting is a simple workaround.
09-09-2004