Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TimerTask and servlet container

 
ben oliver
Ranch Hand
Posts: 375
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I developed a web application deployed to websphere container. I want to create a scheduled job running daily. I want to use JDK TimerTask API for this. But I don't want this job be triggered by the shutdown and/or start up. So, can I still use Timer task for my j2ee web application for daily job ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I understand your question. Why would server startup/shutdown control when your TimerTask is run?
 
Paul Clapham
Sheriff
Pie
Posts: 20158
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ben oliver:
I developed a web application deployed to websphere container. I want to create a scheduled job running daily.
Is there a relationship between these two statements? If so, what is it? Like the other Paul, I don't understand your question.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it really need to run as part of the web app?

For such things in the past I've created stand-alone daemon applications that I can schedule as a cron job and run independently of the web app container.
 
ben oliver
Ranch Hand
Posts: 375
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry it confused you. I want to deploy this Timer task inside the .war or .ear file, for example, create it as a sort of action class and add some properties file to specify the daily run time. What bothers me is -- when my web container starts or shuts down, will it trigger this timer task ? if my .ear gets redeployed will it trigger my timer task ?

For the time being let's assume I don't want to go with cron job type approach. Thanks.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still not clear on what you're asking. The task will be triggered at the time you set it up to be triggered. In a web app, you would do this in the contextInitialized method of a ServletContextListener. If the app is shut down, the task will run no more until the app is restarted/redeployed.
 
ben oliver
Ranch Hand
Posts: 375
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
I'm still not clear on what you're asking. The task will be triggered at the time you set it up to be triggered. In a web app, you would do this in the contextInitialized method of a ServletContextListener. If the app is shut down, the task will run no more until the app is restarted/redeployed.


So if the web app is up running then everything is fine. Suppose I schedule it to run at 8AM daily. Around 6AM today the app is shutdown and it was restarted at 9AM today. So when it restarts, will it skip today's scheduled run and run again tomorrow at 8AM ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be up to you.

If it's something that needs to be run daily but your webserver isn't always running, you might want to log each call to this task in a database or file.
Then, when the app starts up, it can check to see if the task has been run today, if not run it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic