Working Threads in Web Apps
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jorge_Serna
Posted On:   Thursday, March 7, 2002 07:56 AM

Hi, I have a Web Application under Tomcat 4.0.2 which performs several functions under working Threads which run independently from received HTTP requests. I have no problems starting and shutting down the whole server since these Threads are demon Threads and they are released without problems. Unfortunately, if I try to do something similar using Tomcat management features to stop and start applications (the "manager" application), the working Threads stay alive and in the scope of the recently "deceased" ClassLoader (which, as expected, raises several LifeCycle errors). In fact I have checked that after stoping an application, the resources (Classes   More>>

Hi,


I have a Web Application under Tomcat 4.0.2 which performs several functions under working Threads which run independently from
received HTTP requests. I have no problems starting and shutting down the whole server since these Threads are demon Threads and
they are released without problems.


Unfortunately, if I try to do something similar using Tomcat management features to stop and start applications (the "manager"
application), the working Threads stay alive and in the scope of the recently "deceased" ClassLoader (which, as expected, raises several
LifeCycle errors).


In fact I have checked that after stoping an application, the resources (Classes and Object instances) used by the "deceased"
ClassLoader are not released (and I can guarantee that this is not due to the working Threads, since the bulkier objects which should be
collected are not referenced by them and their finalize() method is never called).


If I reestart my application several times I end up getting java.lang.OutOfMemoryErrors which are closely followed by a BUS error and
a core Dump (I'm using a Solaris system).


Is there any way to make sure that the old ClassLoader is collected and collects all loaded resources?


Is there any way to notice or be notified by the Servlet Engine that a whole Application has been stopped/started? This would work fine
with individual Servlets via init() and destroy() methods, but in my environment there are several servlets that use the same resources
and working Threads and I would like to know when to release them.


Thanks,


Jorge

   <<Less

Re: Working Threads in Web Apps

Posted By:   michael_dean  
Posted On:   Wednesday, March 20, 2002 06:59 PM

Q: Is there any way to notice or be notified by the Servlet Engine that a whole Application has been stopped/started?



That's exactly what javax.servlet.ServletContextListener is. Just implement the interface (the contextInitialized(...) and contextDestroyed(...) methods) in some implementation class and configure that class in the deployment descriptor for the web app.


Note that servlet events are new in Servlets 2.3 (but Tomcat 4.x supports Servlets 2.3).

About | Sitemap | Contact