Tomcat 8.0.x
Question:
I am wanting to know the proper way to start a thread from a servlet.

Use Case:
A batch process will call a URL that is a servlet.  The servlet will call a 
processes that will trigger a thread to run to do a particular job.  The thread 
will run for a while.  The servlet will not wait on the thread to finish 
running.  Also the thread that is started is running a processes that requires 
there to only be one of these processes running at any given time.

What I have done:
I created a class I call EmailProcess.  I have a static Boolean flag in the 
class called isWorking that indicates if the process is running.  The class 
extends Runnable.  The class also has a static method to start the thread if 
isWorking flag is false.  I have a servlet that will call the static method in 
EmailProcess to start the thread if possible.

Note: If the Tomcat container decides to clean up the servlet that is called 
that triggers the thread I don't want it to mess with the thread.  I want it to 
keep on running.

Thanks for your advice.

Lance

Reply via email to