Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Long Running Servlet

 
Clarke Kent
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic