aspose file tools*
The moose likes Servlets and the fly likes the availabilty of request object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "the availabilty of request object" Watch "the availabilty of request object" New topic
Author

the availabilty of request object

babu krishnan
Greenhorn

Joined: Jun 09, 2002
Posts: 25
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
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
Take a look:
http://java.sun.com/docs/books/tutorial/servlets/client-interaction/index.html
&
http://java.sun.com/docs/books/tutorial/servlets/lifecycle/
HTH
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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
babu krishnan
Greenhorn

Joined: Jun 09, 2002
Posts: 25
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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the availabilty of request object