I have a web server application runing with JVM, where i manage the class loader. My application have an singleton with a cycle timertask. During the redeployment i clean all the references to Class(es). I look like that my singleton with the timerTask doen't die. I add a finalize method with print. the finalize method was never call. Any solution?
+3
A:
Take a look at the Servlet lifecycle. Your servlet can implement destroy()
, which will get called on unloading. Use that to switch off timers etc.
Note that you can never rely on finalize()
being called.
Brian Agnew
2009-07-15 13:59:46
A:
These things are much easier with Spring and Quartz. In Spring you can define a bean to be a singleton (not exactly the same with the singleton design pattern, but it will serve your needs). Also Quartz is much more powerful/flexible/easy to work with than TimerTask.
Spring will take care redeployment issues for you. You just need to define a destroy method.
kgiannakakis
2009-07-15 14:21:50