Run a thread in a servlet
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   eduardo_picardi
Posted On:   Tuesday, March 4, 2003 01:48 AM

Ciao a tutti, I've got a problem with TOMCAT... I'm developing a J2ME MIDlet that connects via HTTP to a Servlet running in TOMCAT and I want to start a thread inizialized with parameter passed by J2ME client. The execution of the thread must go on after the http response of the Servlet... My question is: if the thread is created by the servlet's method 'processRequest',will its execution go on after the termination of the method? Or will it remain orphan and the execution will be stopped? In other words, if I write in the method processRequest: AlertThread al = new AlertThread(...); al.start(); the execution of the thread will go on after    More>>
			
Ciao a tutti,
I've got a problem with TOMCAT...
I'm developing a J2ME MIDlet that connects via HTTP to a
Servlet running in TOMCAT and I want to start a thread
inizialized with parameter passed by J2ME client.
The execution of the thread must go on after the http
response of the Servlet...
My question is: if the thread is created by the servlet's
method 'processRequest',will its execution go on after the
termination of the method? Or will it remain orphan and the
execution will be stopped?
In other words, if I write in the method processRequest:

AlertThread al = new AlertThread(...);
al.start();

the execution of the thread will go on after the http
response of the servlet to the J2ME client?
I was wondering if the problem could be solved creating a
class called 'AlertManager',having a 'startThread' method
which contains the instructions:
AlertThread al = new AlertThread(...);
al.start();
setting an AlertManager object as a member variable of the
Servlet,to be sure that the object is preserved during the
whole servlet's life-cycle.
Is it correct?
In this way, does the end of the execution of the
method 'processRequest' leave the thread orphan?

Thanx in advance,
Edo
   <<Less

Re: Run a thread in a servlet

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, March 4, 2003 03:18 AM

Ciao Eduardo,

But if you want a thread to live for the entire lifecicle of a Servlet, why don't you have it started in the init() method of the servlet (and stopped in the destroy())?

Or you need to start one thread every time the servlet gets a new request?
About | Sitemap | Contact