Hello,

we have an internal application which also supports printing.
For this reason, we use the following code snippet:

DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintRequestAttributeSet patts = new HashPrintRequestAttributeSet();
PrintServiceLookup.lookupPrintServices(flavor, patts);

This triggers the JDK to spawn two threads, which can be seen in the 
OpenJDK-Sources:
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java
(see around line no 134 ff)
--> Thread thr = new Thread(null, new PrinterChangeListener(), 
"PrinterListener", 0, false);
       ...
      Thread remThr = new Thread(null, new RemotePrinterChangeListener(), 
"RemotePrinterListener", 0, false);

During Undeployment or stopping Tomcat, we therefore get the following 2 
Warnings:

21-Aug-2021 01:11:59.254 WARNUNG [Thread-50] 
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. Stack trace 
of thread:
 
java.desktop@11.0.12/sun.print.PrintServiceLookupProvider.notifyLocalPrinterChange(Native
 Method)
 
java.desktop@11.0.12/sun.print.PrintServiceLookupProvider$PrinterChangeListener.run(PrintServiceLookupProvider.java:316)
 java.base@11.0.12/java.lang.Thread.run(Thread.java:829)

21-Aug-2021 01:11:59.254 WARNUNG [Thread-50] 
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web 
application [ROOT] appears to have started a thread named 
[RemotePrinterListener] but has failed to stop it. This is very likely to 
create a memory leak. Stack trace of thread:
 
java.desktop@11.0.12/sun.print.PrintServiceLookupProvider.notifyRemotePrinterChange(Native
 Method)
 
java.desktop@11.0.12/sun.print.PrintServiceLookupProvider$RemotePrinterChangeListener.run(PrintServiceLookupProvider.java:323)
 java.base@11.0.12/java.lang.Thread.run(Thread.java:829)

Despite the threads are deamonized, the warning is printed.

Is there anything, the application can prevent this?
Should Tomcat maybe skip the warning if the thread is demonized?
Or maybe these threads should be ignored when checking for orphaned threads?

It was tested with Tomcat 9.0.52, Windows 10, Coretto-JDK 11.0.12_7.

Thanks in advance!
Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to