Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

background processing - thread

 
Nidhi Singhal
Ranch Hand
Posts: 89
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to design a servlet that monitors a particular task continously in a loop. For this I am creating a thread that will run in a continous loop monitoring the task. I want to make this a background thread that will exist and keeps on doing it's job even when the servlet is unloaded?
How can I do that? If I create the thread in the servlet's init() method and does not stop it in destroy()... will that make the thread as a background thread? or shall i call setDaemon(true) on that thread to make it a daemon thread?
Please help me out? If there is any other solution to this...please suggest.

Thanks...

Nidhi
 
Bonagiri UmaMaheshwar Rao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are not intrested to stop the service while your servlet is unloaded then you write your service in separate standard java class and create its instance when your context is intialized. (for this you can use ServletContextListener) and your standard java class should implement multithreading. and when your context is destroyed you can stop that service.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic