my dog learned polymorphism*
The moose likes Servlets and the fly likes Long Running Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Long Running Servlet" Watch "Long Running Servlet" New topic
Author

Long Running Servlet

Clarke Kent
Greenhorn

Joined: Dec 19, 2005
Posts: 14
Hi I have a servlet that accesses a MS SQL DB.. It accesses lots of data so it takes a lot of time to finish, about 15 minutes, which is normal.

Now under normal Servlet execution,if i run this servlet, the web browser will be left blank until the process ends. So is there a way or approach to notify the client as to whether this process is in process or has finished?
[ December 19, 2005: Message edited by: Bear Bibeault ]
Prabodh Reddy
Greenhorn

Joined: Dec 19, 2005
Posts: 14
Hi,

Can u send me the code? are u using ServletContextListener?
ServletContextListener will notified when ever application is deployed.
this listener will be called before any servlets or JSP.
u can very well store Database connection inf in the attributes so that other servlets or jsp's in your webapplication can make use of it.

Thanx
Prabodh Reddy
(Sun certified Java Programmer 1.4)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If the process is going to take a long time, (more that 15 or 30 seconds), I like to start it in a separate thread and return the user to a status page immediately. In the status page I have a meta refresh tag that will cause it to refresh every n seconds. Each time it refreshes, it checks on the status. Once the process is done the status page redirects to the completed report. The user should be able to leave the application and come back without interrupting the process.

If the report will take longer than a minute or two, it's also a nice idea to have it email the user when it's done so they don't have to keep checking back for a status.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
As Clarke did mention that it is taking about 15 minutes, it is really a long time to make user keep-on-waiting. As Ben said, it is better to just notify the user over email or have users to goto a page to check the status when they wish (after approx 15 minutes). This would save lots of server resources.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Clarke Kent:
Hi I have a servlet that accesses a MS SQL DB.. It accesses lots of data so it takes a lot of time to finish, about 15 minutes, which is normal.


What you used to do there for 15 mins? Just thought you might need some tuning.
 
 
subject: Long Running Servlet