File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes creating a new thread from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "creating a new thread from servlet" Watch "creating a new thread from servlet" New topic

creating a new thread from servlet

Anupreet Arora
Ranch Hand

Joined: Jun 17, 2003
Posts: 81
I am currently facing a problem with a web application I am supporting.
I actually need to create and show pdf report that is based on the extract of a large amount of data. The extract of the data takes some time and then its formatting and conversion into a pdf report also takes quite some time. The problem is that while the application is doing so, the request times out (currently 2 mins) and the user is takes to a error page.
So we are exploring two options to avoid this problem.
1) Create a new thread from the servlet's service method ( Struts perform method of the action servlet ) which will do the processing for the extract of data and its conversion into a pdf report. And while this is happening, we can send a response to the user.. maybe to a jsp showing the status of the report. When the report has been generated by the separate thread, it will also create a Marker file. The page that was loaded will keep checking for the existence of the marker file. When found, it will load the report into the browser. The process of extract involves calls to EJBs which give calls to methods to connect to database using connection pool, and then extract the data. The pdf is created using third party java API.
My question is that is there any reason why this should not be done... beacause it is usually said that new threads should not be created from servlets. What are the pitfalls of doing this ?
2) Are there any problems with increasing the request time out parameter to say 15 minutes. The report will be generated in that much time comfortably and no error page will be shown to the users.
3) Is there any other approach that anyone will like to suggest for this issue ?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Exactly this sort of question comes up all the time here - browse around in the older posts or do a search and you are bound to find an extensive discussion.
I agree. Here's the link:
subject: creating a new thread from servlet
It's not a secret anymore!