Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multi part resonse from servlet

 
Shubhashis Dasgupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My servlet is doing a long processing job and the request is getting timed out. Can anybody help me about this so that I can send multipart response and my request will not be timed out?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web browsers don't work that way.
The usual approach is to return a page that has automatic refresh turned on. Every few seconds it resends the request, polling the web server. When the web server has the data all ready for transmission, it sends the data instead of the "please wait" page.
I like to further refine this by limiting the polling period to "X"-many minutes worth of polling, just so the user's browser doesn't somehow end up tying up the server polling mindlessly after the user has left for the day. If "X" has expired I put a "Click here to start checking again" button on the polling page.
 
Shubhashis Dasgupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnx Tim. But the problem I am having is something different. My purpose is not to show a "wait" page, but to show some output data after some processing is done and in a regular manner. Let's say a database update(long duration) is done in a loop and after each iteration I need to send some output to the client. Then how can I implement that?
 
Aman Rustogi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can trying flushing out the data from ur output stream after each iteration, to immediatly display the contents on the browser [using out.flush()].
Besides if u r using a Query String to update data, u could try using a stored procedure to do the same which comparatively is much faster than ur plain SQL string.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops. Just reread that. OK, the reason the browser times out is so the user doesn't get locked up is the server goes down. You HAVE to respond in a reasonable time, for the user's sake.
If the process takes longer than that interval, you should pass it off to another (asynchronous) task on the server, THEN use the "wait" mechanism to keep the connection alive, and have the web server check the progress of the process server.
The reason you need a "wait" page is that a web server CAN'T "push" output, only respond to requests, so you just keep sending requests until there's output available. In some cases, you may want to display that output incrementally, as it becomes available, in which case just pass it back as part of the "wait" page. Not the most beautiful solution in the world, I admit, but the only one I know of that works in the general http world.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic