JDK-8150181 : javafx print jobs take 60 times longer than javax.print
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u72,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-02-18
  • Updated: 2020-01-31
  • Resolved: 2016-06-02
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.
JDK 8 JDK 9
8u112Fixed 9Fixed
Related Reports
Relates :  
Description
J2SE Version (please include all output from java -version flag):
java version "1.8.0_75"
Java(TM) SE Runtime Environment (build 1.8.0_75-b07)
Java HotSpot(TM) Client VM (build 25.75-b07, mixed mode)

Does this problem occur on J2SE 6ux or 7ux or 8ux?  Yes / No (pick one)
8U72, maybe more


Operating System Configuration Information (be specific):
HP EliteBook 8760W
Windows 7 Professional 64-bit (SP1)
8G Ram


Bug Description:

Spooling print jobs takes far too long.  Using the javax.print libraries, a 
print job where can spool 1053 pages in less than 15 seconds.  Using the new 
javafx libraries, this takes about 20 minutes.  This calculates being to over 
60 times slower than the javax.print APIs.  

Realize that printing, in general, is limited to the physical printing of the 
pages, but the user experience here is a factor as well.  Previously, a user 
could start a print, wait 15 seconds, exit the application, and then just 
wait for the printer to finish.

An instance where this may be even more of a factor is printing to a virtual 
printer, like a "Print to PDF" printer.  Doing this on my desktop, printing 
to a PDF file does not add any appreciable amount of time, so I have my 1053 
page PDF ready to go in roughly 15 seconds.  With the javafx API, this would 
take 20 minutes of actual user time.

One option would be to make the wait time smaller.  There are some 1 second 
waits in the print code, which is far too long in my situation.

A better possibility would be to make the notify() more aggressive.  In 
waitForNextPage(), "pageDone" is set to true, but never notifies threads 
waiting on it to wake up.  This seems like an oversight.  Since a thread is 
waiting on this flag, like implPrintPage(), it seems like code changing the 
value of this flag should notify it so it can re-check the value.

The proposed change seems as safe as the existing code, since nothing in the 
existing code prevents the printing thread from sporadically waking up at 
this point anyway.  This change would just encourage that to happen every 
time.
 
private boolean waitForNextPage(int pageIndex) {
<snip>
pageDone = true;
<snip>
currPageInfo = newPageInfo;
newPageInfo = null;
currPageIndex = pageIndex;
currPageFormat = getPageFormatFromLayout(currPageInfo.getPageLayout());
//Suggested Addition Start
synchronized (monitor) {
monitor.notify();
}
//Suggested Addition End
return true;
}

       private void implPrintPage(PageLayout pageLayout, Node node) {
 <snip>
               while (!pageDone) {
                    synchronized (monitor) {
                        try {
monitor.wait(1000);
                        } catch (InterruptedException e) {
                        }
}
<snip>
}



Comments
Approved to backport to 8u-dev for 8u112.
02-06-2016

Changeset: 5fd2fa90dd7b Author: prr Date: 2016-06-02 14:29 -0700 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/5fd2fa90dd7b 8150181: javafx print jobs take 60 times longer than javax.print Reviewed-by: prr ! modules/graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinterJob.java + tests/manual/printing/PrintPerformanceTest.java
02-06-2016

The fix looks OK to me, but I want Phil to review it.
27-04-2016

Fixing the component / sub-component to javafx/graphics. The review for 9 is still ongoing. Once done and pushed to 9 I will review it for backport to 8u-dev.
27-04-2016

CAP member has confirmed the jar file we provided fixed all their problem and this issue can be closed as fixed. Can it back port to 8u update releases.
27-04-2016

review thread: http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-April/018933.html
25-04-2016

webrev: http://cr.openjdk.java.net/~mcherkas/8150181/9/webrev.00/ Javafx print is slow because after sending node for printing we wait 1 sec before checking that page was done, see implPrintPage method: while (!pageDone) { synchronized (monitor) { try { monitor.wait(1000); } catch (InterruptedException e) { } } } so if you need to print 100 pages to pdf you will have to wait for 100 seconds while with javax.print it happens almost instantly. I added "notify" when page is printed, so now we start a new printing without waiting.
19-04-2016

Change the priority to be P2 due that it is a critical issue for the CAP member and would like have the fix asap.
02-03-2016