On 18/08/2011 22:22, Dan Armbrust wrote:
> On Thu, Aug 18, 2011 at 2:13 PM, Christopher Schultz
> <ch...@christopherschultz.net> wrote:
> 
>> The JVM should not launch more than one AWT thread, so you should be
>> okay. The only issue would be whether or not it inherits the webapp's
>> context ClassLoader which would really represent a memory leak if you
>> do live webapp reloads (or undeploy/redeploy).
>>
>> You would only get this message if the WebappClassLoader was being
>> used as the ContextClassLoader for this thread, so that must be the case.
>>
>> You should be able to trick the AWT thread to start using the system
>> class loader in a ServletContextListener that looks something like this:
>>
>> init() {
>>
>>  Thread myThread = Thread.currentThread();
>>  ClassLoader ccl = myThread.getContextClassLoader(); // PUSH
>>  myThread.setContextClassLoader(ClassLoader.getSystemClassLoader());
>>
>>  // do something that triggers the creation of the AWT -- maybe
>>  // something like "new java.awt.Frame()"
>>
>>  myThread.setContextClassLoader(ccl); // POP
>> }
>>
>> This will pin the system ClassLoader into memory (big deal) instead of
>> your webapp's. This should fix this particular leak and, by extension,
>> remove the error message from your logs.
>>
>> - -chris
> 
> You sir, are a clever clever man :)
> 
> Works perfectly.  The AWT thing that I did was simply
> 
> Toolkit.getDefaultToolkit().createImage(new byte[]{});
> 
> which avoids "Headless" issues, but still kicks off the AWT-Windows thread.
> 
> And since it is no longer tied to the context class loader, Tomcat
> doesn't detect any issues on shutdown.

Doesn't the leak prevention listener do this?


p



Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to