• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TimerTask, Threads and Servlets

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is a TimerTask a Thread? Reason I ask is this. I'm creating a TimerTask to execute some code on a daily basis. AND is the TimerTask outside of the Servlet container. If it is, what kind of TimerTask like object can I create so it is INSIDE of the web container?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dale,
Take a look at the following article.
It goes over several approaches for running jobs within Java apps; including java.util.timer and Quartz.
http://www.onjava.com/pub/a/onjava/2004/03/10/quartz.html
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't look like this solution provides me with a way of scheduling a task that will occur within a web container. I'm looking for something that I can control by restarting my web container. This way its safe for the company.
 
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't read the article, but was there something in it that said "You can't use a Timer in a web container"? Because you can use a Timer in a web container. Maybe you just didn't see an explicit example of doing that? If you want to start a Timer when a web application starts up, then you could do so in the contextInitialized() method of a ServletContextListener.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dale DeMott:
It doesn't look like this solution provides me with a way of scheduling a task that will occur within a web container. I'm looking for something that I can control by restarting my web container. This way its safe for the company.



What did you see in there that leads to to believe that this couldn't be done from within a web container?
A web container is a Java app.

You could certainly embed either solution (quartz or java.util.timer) into a context scoped object that gets instanciated via a contextListener.
There are some things to watch out for (daemon vs non-daemon threads, etc..) but these are typical issues when starting your own threads from within a webapp.

[KLUNK!!]
[ May 18, 2006: Message edited by: Ben Souther ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic