wood burning stoves*
The moose likes Servlets and the fly likes Thread Issue In The Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Thread Issue In The Servlet" Watch "Thread Issue In The Servlet" New topic
Author

Thread Issue In The Servlet

Khirod Patra
Greenhorn

Joined: Mar 27, 2008
Posts: 23
Hi,

In a Servlet ,I want to execute a method as a background process.I used this method inside the Servlet becase It use the
request object.So I create a Thread through a inner class inside the servlet. The Thread execute and works fine upto the servlet
has not been redirect to jsp,The moment it redirect the run() method from Thread returns NullPointerException.

So Here what I need

I want to execute the Thread with out depends the redirection of servlet.I mean as a backgroud process.In the Thread I have to use the request object of the Servlet.

Let me Know if anything required from myside..

Please Help me Out..


Thanks & Regards
Khirod Patra
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I used this method inside the Servlet becase It use the request object.


NO - do NOT keep a reference to the request object - it must be managed by the servlet container. It is time to redesign!

You will find that the servet API provides simple methods for extracting ALL of the information in a request if you have to provide this to another process.

Bill
Khirod Patra
Greenhorn

Joined: Mar 27, 2008
Posts: 23
Thanks for the response,

Is there any other way , That we can manage a dummy request object for this job



Thanks & Regards

Khirod Patra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41115
    
  45
What do you need the request object for? As Bill said, you can get all the information from it, pass those to the background job, and then let it do its work. Servlet API objects should only be used in the view layer, not in the deeper layers.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Issue In The Servlet
 
Similar Threads
IllegalStateException: Cannot forward a response that is already committed
Servlet request
Different ContextRoot ..??
Servlet to html
MVC without use of Struts