Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems shutting down tomcat with timer running  RSS feed

 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I've created a class that loads on startup and performs maintainance activities once daily, and I've used both the Timer and TimerTask classes.
This class works perfectly for me except on my local machine I can't shut Tomcat down with it running. I haven't uploaded it to the live server yet and I'm worried I'll have the same problem. Is their something I'm missing? I didn't create a cancel method for this class as it's needed to perform its tasks every day, and in fact that's why it's set up to load-on-startup...in case the server ever crashes it will automatically restart when the server does.
Any help or suggestions is greatly appreciated. Thanks,
-Pat
 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, should I decide to add other tasks that run on different schedules what would be the best way to go about this? Here is the shell of the code I'm using now:

If I wanted to add other tasks, could I just create another TimerTask object and Timer in this page as well?
Thanks again for any suggestions,
-Pat
 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help!
I'm really stuck on my first question about not being able to shutdown Tomcat. I can't find similar problems anywhere on this site or google, and to be honest I don't want to upload my class to my live server until I know what's causing this.
I thought this might be the most appropriate topic to pose this question and would really appreciate any suggestions. TIA,
-Pat
 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I figured it out myself here, so I am posting this incase anyone else ever has trouble.
I never defined a destroy() method for this class so the Timer kept trying to run, which I guess is what was preventing Tomcat from completely shutting down.
The solution to my problem was simply adding this:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!