Hello Pradip,
   Thanks for the comments. Could you please clarify the statement "the servlet 
can enque the data in a concurrent queue, and then
notify the object " ? Would you assume that there would be two threads in the 
servlet ? One is context listener thread, and the other is enqueue data thread ?
Thanks,
Tom
________________________________________
From: Pradip Bhattacharya [pradip.bhattacha...@gmail.com]
Sent: Tuesday, July 18, 2017 10:09 AM
To: Tomcat Users List
Subject: Re: run thread from servlet

Hello,
I hope I understood the requirement correctly. I believe you can start
EmailProcess thread by the context listener. This thread can wait on an
object. And the servlet can enque the data in a concurrent queue, and then
notify the object, on which EmailProcess thread is waiting.
Is this EmailProcess is an asynchronous service to send emails ?
Regards
Pradip.B

On Jul 18, 2017 7:27 PM, "Campbell, Lance" <la...@illinois.edu> wrote:

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

________________________________

This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to