Hi all, I have a doubt. I requset for an action to my servlet, and servlet spawns a thread for my request. That thread calls my service method (If iam correct) and in that iam calling an action class to server that request. Here in the action class i spawn a thread to do the task and i come out of service method and redirects to a page. My question is if the thread which iam spawning in my action class takes some time and meanwhile my service method is over and i get a response, what happens to my thread's life. As the request object's life itself is over(i suppose),which is parent how can my child thread runs? Please reply ASAP. Thanx to all
Generally speaking you need to do everything with the Thread that the Servlet Engine (ie Tomcat etc) provides when it calls the service method. It is perfectly possible to start more Threads from a servlet but you should never start your own Thread unless you really know what you are doing. You are correct about the request object - the lifetime of a request object is managed by the servlet container, you should not try to hang on to it. Bill
Joined: Jun 09, 2002
Hi all, I think still my question is not fully answered. What happens if my action class spawns a thread and my servlet's service method is over and redirects to some other page and what happens to my request object. Does it die OR does my requested action completes or not.(My requested action completes only when the thread which i spawned completes its run method)
Your answer would be greatly helpful on this.
Author and all-around good cowpoke
Joined: Mar 22, 2000
After the response has been generated and the servlet Thread exits the service method, the servlet engine can do what it likes with the request object. It is my understanding that for efficiency, typical servlet engines re-cycle the request object by some sort of process that drops all parameters and attributes that were attached during request processing. You must not count on anything remaining valid in a request object after the response is sent. Any Thread started during processing will ontinue until the run method is exited. There is nothing magic about Threads created during request processing. You must be very careful about the servlet Thread, if you tie it up - by join()ing another Thread, for instance, it could interfere with the servlet engine's response to other requests. Bill