This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes background processing - thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "background processing - thread" Watch "background processing - thread" New topic

background processing - thread

Nidhi Singhal
Ranch Hand

Joined: Sep 19, 2004
Posts: 89

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.


Bonagiri UmaMaheshwar Rao

Joined: Mar 27, 2005
Posts: 12
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.
I agree. Here's the link:
subject: background processing - thread