United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4744405 RFE: lookupPrintServices() to refresh the printers list dynamically
JDK-4744405 : RFE: lookupPrintServices() to refresh the printers list dynamically

Details
Type:
Enhancement
Submit Date:
2002-09-10
Status:
Resolved
Updated Date:
2005-04-18
Project Name:
JDK
Resolved Date:
2005-04-18
Component:
client-libs
OS:
solaris_8,linux,windows_xp,windows_2000
Sub-Component:
2d
CPU:
x86,sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0,1.4.1,1.4.2,5.0u6,5.0u14
Fixed Versions:

Related Reports
Backport:
Backport:
Duplicate:
Duplicate:
Duplicate:
Relates:

Sub Tasks

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
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.
                                     
2004-09-09
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
                                     
2005-03-28



Hardware and Software, Engineered to Work Together