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
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.