Details
-
Bug
-
Resolution: Fixed
-
P4
-
7, 8, 11, 17, 18
-
b22
-
generic
-
generic
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8319675 | 17.0.10 | Sergey Bylokhov | P4 | Resolved | Fixed | b03 |
JDK-8329206 | 11.0.24 | Ben Taylor | P4 | Resolved | Fixed | b01 |
Description
ADDITIONAL SYSTEM INFORMATION :
Tested under Tomcat 9.0.52, Windows 10, Coretto-JDK 11.0.12_7
A DESCRIPTION OF THE PROBLEM :
We are using Tomcat 9 and our application uses the following code snippet:
DocFlavor flav = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService[] printers = PrintServiceLookup.lookupPrintServices(flav, null);
The underlying PrintServiceLookupProvider will spawn 2 threads, namely "PrinterListener" and "RemotePrinterListener" (around line 134 in sun.print.PrintServiceLookupProvider).
These two threads are connected to the classloader of the web-application.
During undeployment the classloader gets removed together with the two orphaned threads.
Tomcat issues a warning on undeployment:
"org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [PrinterListener] but has failed to stop it. This is very likely to create a memory leak. "
The two threads should not be started in the current classloaders context because that classloader might get deleted on web applications.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the two lines within e.g. a jsp-page within Tomcat:
DocFlavor flav = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService[] printers = PrintServiceLookup.lookupPrintServices(flav, null);
Undeploy the application and the catalina.log will report the two orphaned threads which get killed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application should either be able to get a handle to these threads for a clean shutdown or maybe a flag to prevent starting these two threads.
Another option would be to attach the threads to the root classloader to prevent problems during undeployment of web applications.
ACTUAL -
The two threads are recognized as orphaned and are forcely closed by web container.
CUSTOMER SUBMITTED WORKAROUND :
Before calling PrintServiceLookup.lookupPrintServices(...) we now change the thread's classloader to the parent and afterwards resetting the thread's classloader to the original one.
FREQUENCY : always
Tested under Tomcat 9.0.52, Windows 10, Coretto-JDK 11.0.12_7
A DESCRIPTION OF THE PROBLEM :
We are using Tomcat 9 and our application uses the following code snippet:
DocFlavor flav = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService[] printers = PrintServiceLookup.lookupPrintServices(flav, null);
The underlying PrintServiceLookupProvider will spawn 2 threads, namely "PrinterListener" and "RemotePrinterListener" (around line 134 in sun.print.PrintServiceLookupProvider).
These two threads are connected to the classloader of the web-application.
During undeployment the classloader gets removed together with the two orphaned threads.
Tomcat issues a warning on undeployment:
"org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [PrinterListener] but has failed to stop it. This is very likely to create a memory leak. "
The two threads should not be started in the current classloaders context because that classloader might get deleted on web applications.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the two lines within e.g. a jsp-page within Tomcat:
DocFlavor flav = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService[] printers = PrintServiceLookup.lookupPrintServices(flav, null);
Undeploy the application and the catalina.log will report the two orphaned threads which get killed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application should either be able to get a handle to these threads for a clean shutdown or maybe a flag to prevent starting these two threads.
Another option would be to attach the threads to the root classloader to prevent problems during undeployment of web applications.
ACTUAL -
The two threads are recognized as orphaned and are forcely closed by web container.
CUSTOMER SUBMITTED WORKAROUND :
Before calling PrintServiceLookup.lookupPrintServices(...) we now change the thread's classloader to the parent and afterwards resetting the thread's classloader to the original one.
FREQUENCY : always
Attachments
Issue Links
- backported by
-
JDK-8319675 PrintServiceLookup spawns 2 threads in the current classloader, getting orphaned
- Resolved
-
JDK-8329206 PrintServiceLookup spawns 2 threads in the current classloader, getting orphaned
- Resolved
- links to
-
Commit openjdk/jdk11u-dev/41179534
-
Commit openjdk/jdk17u-dev/5cb86e3f
-
Commit openjdk/jdk/68756782
-
Review openjdk/jdk11u-dev/2623
-
Review openjdk/jdk17u-dev/1625
-
Review openjdk/jdk/5939
(3 links to)