JDK-4970885 : Java 1.4.2_02 printing failing/is very slow on code which works fine on 1.3.1 on
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2_02
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2003-12-19
  • Updated: 2004-03-11
  • Resolved: 2004-03-11
Related Reports
Duplicate :  
Description
Customer has a java swing application running fine on 1.3.1.  Since upgrading to 1.4.2_02, printing has been very slow and they encounter this problem.

The problem manifests itself in inability to print.  Printer Status dialog would show that document is being spooled, but it never finishes spooling.  "Killing" JVM releases the document, and it prints 
successfully.  After several attempts to print, printing from other applications becomes affected.  For example, printing from Notepad results in error message "The Handle is Invalid".  The only solution after that is to re-boot the machine.

The printouts are text only (there is no graphics) - basically, trade information in a tabular format. 

There is nothing fancy about them. The application is a standalone Swing Java application, so they are using Java printing API. As far as fonts are concerned, they are using common ones - Serif and SanSerif.

Here are their questions:
a) What DLLs are responsible for communication between Swing application and OS / printer driver?
b) Did any of those DLLs change from JRE 1.3.1 and JRE 1.4.2?
c) We get PrintJob by using getToolkit().getPrintJob(), and it seems to give us a "bad" printer handle that causes spooling to hang. What are Sun's recommendation on getting and using PrintJob class?
d) Were any of the printing classes deprecated or taken out for 1.4.2 release, since JDK 1.4.2 introduced new Printing API?

Here is their test case:
---------------------------------------------

import java.awt.*;
import java.awt.event.*;

public class PrintingTest
    extends Frame
    implements ActionListener{
    public PrintingTest()    {
        super("Printing Test");
        Button b = new Button("Print");
        b.setActionCommand("print");
        b.addActionListener(this);
        add("Center", b);
        pack();
    }

    public void actionPerformed(ActionEvent e)    {
        String cmd = e.getActionCommand();
        if (cmd.equals("print"))        {
            PrintJob pjob = getToolkit().getPrintJob(this,
                               "Printing Test", null, null);
            if (pjob != null) {
               for (int page = 0 ; page < 2; page++ )   {
                  Graphics pg = pjob.getGraphics();
                  Point currentPrintPosition;
                  currentPrintPosition = new Point(0,0);
                  currentPrintPosition.move(20,35);
                  if (pg != null)   {
                     pg.setColor(Color.black);
                     pg.setFont(new Font("SanSerif", Font.BOLD, 8));
                     for (int i = 0; i < 3; i++)   {
                        pg.drawString("Hello World", currentPrintPosition.x,
                        currentPrintPosition.y);
                        currentPrintPosition.x += 20;
                        currentPrintPosition.y += 35;
                     }
                     pg.dispose(); // flush page
                  }
               }
               pjob.end();
            }
            System.exit(0);
        }
    }
    public static void main(String args[])    {
        PrintingTest test = new PrintingTest();
        test.show();
    }
}

This only affects Windows NT boxes, the customer has Windows 2000 and XP, are not affected.

###@###.### 2003-12-18

Comments
EVALUATION I'll commit this to tiger since it has been escalated. We'll wait for CTE to provide the fix. ###@###.### 2004-01-05 Name: rpR10076 Date: 03/10/2004 According to ###@###.### and ###@###.###, the fix for 4968560 also resolved the problems the customer was seeing. Though none of those two bugs could be reproduced in tiger, we believe this is mostly due to thread timing issues, and fix for 4968560 will be integrated into both tiger and 1.4.2_05. I am going to close this bug as a diplicate of 4968560 based on the information I got from CTE engineers. ###@###.### ======================================================================
11-06-2004