添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
性感的生菜  ·  USAJOBS - Search·  5 月前    · 
想出家的葫芦  ·  ROG STRIX B760-F ...·  5 月前    · 
越狱的鼠标  ·  WPF ...·  8 月前    · 
有爱心的灌汤包  ·  DS Avocats·  8 月前    · 
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