You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Delbecq <de...@oma.be> on 2006/11/09 14:08:02 UTC

Preventing memory leaks with awt event thread, is it possible?

Hello,

playing with a webapplication that requires awt to do some graphical
operation, i noticed this.

1) Servlet invoked by http-thread 69 request an awt operation
2) AWT initializes and starts it's awt event queue thread.
3) As part of the thread initialisation process, the contextClassLoader
of the AWT event queue thread is set as the one of the calling thread,
that is the one of http-thread 69, which has been set by tomcat to
webappClassLoaderXXX
4) undeploy webapp.

At this moment, because the awt event queue won't stop until jvm stops,
the webappClassLoaderXXX stays referenced until the  terminaison of the
java process, which mean every class and static fields are not garbage
collected. If the webapp had a memory footprint of 35M, there are 35M
stuck in java memory.

Is there a way to avoid this? One possibility could be to arrange for
awt thread to run in the context class loader of tomcat server, not the
one of a web application, but then you have to find some way to force
tomcat into initializing awt (and not the first webapp that requires awt).

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by David Delbecq <de...@oma.be>.
Mikolaj Rydzewski a écrit :
> David Delbecq wrote:
>> Is there a way to avoid this? One possibility could be to arrange for
>> awt thread to run in the context class loader of tomcat server, not the
>> one of a web application, but then you have to find some way to force
>> tomcat into initializing awt (and not the first webapp that requires
>> awt).
>>   
> Maybe headless=true property (or sth similiar, there is one) would help?
>
>
Nope, need a fully functionnal awt for the rendering :)

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David,

David Delbecq wrote:
> Christopher Schultz a écrit :
>> To run Java AWT on a server like this, he'd already have to be doing
>> this. :(
> Nope, we don't want headless awt, it's pretty as usefull as no AWT.
> Whenever you create any Component you get headless exception :)
> (For background information, we are rendering a visual using JGraph, it
> can't run in headless environments)

Ouch. So, you have to have X running on your server as well? There goes
a bunch of memory...

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFVH+C9CaO5/Lv0PARArvAAJ0SqQ3OvZUui8hNY7xnXHJt7eRkNwCgg7bQ
Tp/hxSqAT3vMOKkFc8qJ+PI=
=lNI9
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by David Delbecq <de...@oma.be>.
Christopher Schultz a écrit :
> Mikolaj,
>
> Mikolaj Rydzewski wrote:
> > Maybe headless=true property (or sth similiar, there is one) would help?
>
> To run Java AWT on a server like this, he'd already have to be doing
> this. :(
Nope, we don't want headless awt, it's pretty as usefull as no AWT.
Whenever you create any Component you get headless exception :)
(For background information, we are rendering a visual using JGraph, it
can't run in headless environments)
>
> -chris
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mikolaj,

Mikolaj Rydzewski wrote:
>
> Maybe headless=true property (or sth similiar, there is one) would help?

To run Java AWT on a server like this, he'd already have to be doing
this. :(

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFU7sE9CaO5/Lv0PARAiEyAJwPIMADI1DEnmfhj7WBbcbeYkrNMACeOXti
dPxxP+btQzgyC1Z/mFka7VY=
=FdiZ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
David Delbecq wrote:
> Is there a way to avoid this? One possibility could be to arrange for
> awt thread to run in the context class loader of tomcat server, not the
> one of a web application, but then you have to find some way to force
> tomcat into initializing awt (and not the first webapp that requires awt).
>   
Maybe headless=true property (or sth similiar, there is one) would help?


-- 
Mikolaj Rydzewski <mi...@ceti.pl>


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by David Delbecq <de...@oma.be>.
Caldarale, Charles R a écrit :
>> From: David Delbecq [mailto:delbd@oma.be] 
>> Subject: Preventing memory leaks with awt event thread, is it 
>> possible?
>>
>> One possibility could be to arrange for awt thread to run in 
>> the context class loader of tomcat server, not the one of a 
>> web application, but then you have to find some way to force
>> tomcat into initializing awt (and not the first webapp that 
>> requires awt).
>>     
>
> Perhaps you could declare a <Listener> class under <Server> that
> initializes AWT.  This should run independently of any webapp.
>   
I'll give it a try :D
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by David Delbecq <de...@oma.be>.
We had no choice but running it on the webapp server. It requires quite
a few interaction with datas provided by libraries in webapp. We don't
redeploy often, but we try to avoid stopping other webapplications when
redeploying.

Thank all for advices.
Christopher Schultz a écrit :
> David,
>
> Caldarale, Charles R wrote:
> >> From: David Delbecq [mailto:delbd@oma.be]
> >> Subject: Preventing memory leaks with awt event thread, is it
> >> possible?
> >>
> >> One possibility could be to arrange for awt thread to run in
> >> the context class loader of tomcat server, not the one of a
> >> web application, but then you have to find some way to force
> >> tomcat into initializing awt (and not the first webapp that
> >> requires awt).
> > Perhaps you could declare a <Listener> class under <Server> that
> > initializes AWT.  This should run independently of any webapp.
>
> Other things to consider are:
>
> 1. How often you actually use the AWT
> 2. How often you hot-re-deploy your webapp
>
> For instance, if you hardly ever use the AWT, then perhaps you should
> have an external process that handles this operation. You could maybe
> use a batch job, or even spawn a command-line program that does your
> dirty work.
>
> If you use the AWT a lot, perhaps an "AWT server" is what you need...
> sprinkle a little localhost-only TCP/IP into a separate process that
> runs independently of Tomcat. This could be a long-running process that
> eats up only its own memory and not that of your webapp.
>
> Finally, if you hardly ever hot-re-deploy your webapp, I just wouldn't
> worry too much. For exmaple, whenever we upgrade our apps in production,
> we shut down Tomcat and the JVM entirely, load the new code, and start
> back up. In that case, the re-deploy scenario isn't an issue (even if
> it's true that re-deploying "wastes" memory).
>
> Personally, I would be leery of running an AWT instance within a
> production webapp, simply due to the memory and CPU consumption issues
> it raises. I'm sure that it's way more stable than it used to be, but
> it's hairier than the hashtables-and-JDBC world of the standard webapp.
> Just my two cents.
>
> -chris

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Preventing memory leaks with awt event thread, is it possible?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David,

Caldarale, Charles R wrote:
>> From: David Delbecq [mailto:delbd@oma.be] 
>> Subject: Preventing memory leaks with awt event thread, is it 
>> possible?
>>
>> One possibility could be to arrange for awt thread to run in 
>> the context class loader of tomcat server, not the one of a 
>> web application, but then you have to find some way to force
>> tomcat into initializing awt (and not the first webapp that 
>> requires awt).
> 
> Perhaps you could declare a <Listener> class under <Server> that
> initializes AWT.  This should run independently of any webapp.

Other things to consider are:

1. How often you actually use the AWT
2. How often you hot-re-deploy your webapp

For instance, if you hardly ever use the AWT, then perhaps you should
have an external process that handles this operation. You could maybe
use a batch job, or even spawn a command-line program that does your
dirty work.

If you use the AWT a lot, perhaps an "AWT server" is what you need...
sprinkle a little localhost-only TCP/IP into a separate process that
runs independently of Tomcat. This could be a long-running process that
eats up only its own memory and not that of your webapp.

Finally, if you hardly ever hot-re-deploy your webapp, I just wouldn't
worry too much. For exmaple, whenever we upgrade our apps in production,
we shut down Tomcat and the JVM entirely, load the new code, and start
back up. In that case, the re-deploy scenario isn't an issue (even if
it's true that re-deploying "wastes" memory).

Personally, I would be leery of running an AWT instance within a
production webapp, simply due to the memory and CPU consumption issues
it raises. I'm sure that it's way more stable than it used to be, but
it's hairier than the hashtables-and-JDBC world of the standard webapp.
Just my two cents.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFU7x/9CaO5/Lv0PARAoQqAJ9dDZyVRq+tlJL21y0tWo7YbjVcdACfakG4
fiZmOVBfTqTfe79V7S4NJNw=
=Gz8X
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Preventing memory leaks with awt event thread, is it possible?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Delbecq [mailto:delbd@oma.be] 
> Subject: Preventing memory leaks with awt event thread, is it 
> possible?
> 
> One possibility could be to arrange for awt thread to run in 
> the context class loader of tomcat server, not the one of a 
> web application, but then you have to find some way to force
> tomcat into initializing awt (and not the first webapp that 
> requires awt).

Perhaps you could declare a <Listener> class under <Server> that
initializes AWT.  This should run independently of any webapp.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org