Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4744405
Votes 16
Synopsis RFE: lookupPrintServices() to refresh the printers list dynamically
Category java:classes_2d
Reported Against 1.4 , b01 , 1.4.1
Release Fixed mustang(b33), 5.0u18-rev(b05) (Bug ID:2160388) , 5.0u19(b02) (Bug ID:2176462)
State 10-Fix Delivered, request for enhancement
Priority: 4-Low
Related Bugs 6289652 , 5028849 , 6729875 , 6835077 , 6182986 , 5033703
Submit Date 10-SEP-2002
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 ----------//
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.
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.

  xxxxx@xxxxx   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
  xxxxx@xxxxx   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.
  xxxxx@xxxxx   2005-03-28 22:50:23 GMT

  xxxxx@xxxxx   2005-03-29 17:16:05 GMT
Comments
  
  Include a link with my name & email   

Submitted On 06-MAR-2003
A1972
This is a very serious BUG! Since we are running a
TaskServer with many different Java Tasks (realized by
different class Loaders) on a Linux machine. One of that
taks is a PrintServer that prints out reports. 
The only way to configure a printer at the moment is to
restart the whole TaskServer (the complete virtual machine)
which stops all Tasks. 

Please fix it.



Submitted On 02-JUN-2003
ninesun
There are so many bugs in the new print service of JDK1.4.


Submitted On 14-JUN-2004
SeS
I use Windows and with printerJob.printDialog() the list is up to date, but with printerJob.printDialog(attributes) itīs not. The dialog without the attributes seems to be the native one.
Itīs difficult to explain to an end-user, why the printer dialog at one place is up-to-date while it is not up-to-date somewhere else just because there are some additional attributes necessary.


Submitted On 14-JUN-2004
lbrucher
Please, at least provide a method or something to allow the retrievaal of an up-to-date list of printers.
The current situation is not acceptable in a server environment!


Submitted On 16-SEP-2004
simexel
I unferstand the Sun team's issue with Solaris. 
However, we are suffering from this problem in a Win32 environment using JBoss where "restarting the app" is not a feasible option.  Can we perhaps instead have some kind of "cache clearing" feature to the lookupPrintServices method that would work for win32 and linux ?


Submitted On 12-APR-2005
fuggly
Forget Server Side Printing with Citrix under Windows then? 
If there is a printer spooler as a single process running on a Windows server, it will never see the printers of a new user logging in, although Citrix maps the user


Submitted On 12-APR-2005
fuggly
Forget Server Side Printing with Citrix under Windows then? 
If there is a printer spooler as a single process running on a Windows server, it will never see the printers of a new user logging in, although Citrix maps the user's printers into the account the print spooler is started with. Citrix users can then basically forget printing with Java as without manual refresh, Java printing is *totally unusable* for Citrix users.


Submitted On 12-APR-2005
fuggly
On 1.4.2, a (hack-) workaround could be this:

  public void refreshSystemPrinterList() {
    try {
      Class[] classes = PrintServiceLookup.class.getDeclaredClasses();
      for (int i=0; i<classes.length; i++)
        if ("javax.print.PrintServiceLookup$Services".equals(classes[i].getName())) {
          AppContext.getAppContext().remove(classes[i]);
          break;
        }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }


Submitted On 13-APR-2007
SeS
I'm running 1.6.0_01 on Windows XP and my printer list doesn't seem to get updated. Still you need to run fluggy's workaround to see a change.
Does the new feature need to get activated somehow or is it simply not working - any other experiences?


Submitted On 02-NOV-2007
Quirin@DRX
Due to the severity of this bug for server-side printing I request to backport the fixture done in mustang also for tiger.


Submitted On 10-JUL-2008
Atila
Thank you fuggly, your workaround works perfectly.


Submitted On 24-JUL-2008
Is there a permanent fix for this? We have an application which needs to refresh printer lists attached locally once, twice, or even multiple times during the day. We are using jdk1.6.05 which i thought would have addressed this. Right now our only alternative is to simply restart the JVM, not a good solution.



PLEASE NOTE: JDK6 is formerly known as Project Mustang