--- old/src/java.desktop/share/classes/sun/print/PrintJob2D.java 2016-03-01 16:28:30.695528700 +0530 +++ new/src/java.desktop/share/classes/sun/print/PrintJob2D.java 2016-03-01 16:28:30.071527600 +0530 @@ -294,6 +294,7 @@ * This is different than the applications thread. */ private Thread printerJobThread; + private boolean printFinished; public PrintJob2D(Frame frame, String doctitle, final Properties props) { @@ -790,16 +791,21 @@ /* We'll block here until a new graphics becomes * available. */ - currentGraphics = graphicsToBeDrawn.pop(); + if (currentGraphics == null && printFinished) { + synchronized (this) { + startPrinterJobThread(); + notify(); + } + currentGraphics = graphicsToBeDrawn.pop(); + } if (currentGraphics instanceof PeekGraphics) { - ( (PeekGraphics) currentGraphics).setAWTDrawingOnly(); + ((PeekGraphics) currentGraphics).setAWTDrawingOnly(); graphicsDrawn.append(currentGraphics); currentGraphics = graphicsToBeDrawn.pop(); } - if (currentGraphics != null) { /* In the PrintJob API, the origin is at the upper- @@ -829,7 +835,6 @@ this); } - return printGraphics; } @@ -983,12 +988,14 @@ result = NO_SUCH_PAGE; } + return result; } private void startPrinterJobThread() { printerJobThread = new ManagedLocalsThread(this, "printerJobThread"); printerJobThread.start(); + printFinished = false; } @@ -1003,8 +1010,9 @@ /* Close the message queues so that nobody is stuck * waiting for one. */ - graphicsToBeDrawn.closeWhenEmpty(); - graphicsDrawn.close(); + printFinished = true; + //graphicsToBeDrawn.closeWhenEmpty(); + //graphicsDrawn.close(); } private class MessageQ { @@ -1059,6 +1067,9 @@ notify(); } else { + if (printFinished) { + break; + } try { wait(2000); } catch (InterruptedException e) {