File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Thread Issue In The Servlet

Khirod Patra

Joined: Mar 27, 2008
Posts: 23

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

Joined: Mar 22, 2000
Posts: 13024
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.

Khirod Patra

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

Joined: Mar 22, 2005
Posts: 42959
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.
I agree. Here's the link:
subject: Thread Issue In The Servlet
jQuery in Action, 3rd edition