java - Get status of servlet request before the response is returned - Stack Overflow

Good evening,I am in the process of writing a Java Servlet (Struts 2, Tomcat, JSP etc) which is capable

Good evening,

I am in the process of writing a Java Servlet (Struts 2, Tomcat, JSP etc) which is capable of doing some fairly plex simulations. These can take up to 2 minutes to plete on the and will return a graph of the results. It is trivial to calculate the percentage of the simulation pleted because the process works by repeating the same calculations 1000s of times.

I would be interested to know if anyone has ever tried to use client side technology to provide any estimate of the percentage plete. I.e query the servlet processing to get the number of cycles pleted at various point throughout the simulation. This could then be displayed as a bar in the client browser.

Any thoughts, advice, resources would be much appreciated.

Thanks,

Alex

Good evening,

I am in the process of writing a Java Servlet (Struts 2, Tomcat, JSP etc) which is capable of doing some fairly plex simulations. These can take up to 2 minutes to plete on the and will return a graph of the results. It is trivial to calculate the percentage of the simulation pleted because the process works by repeating the same calculations 1000s of times.

I would be interested to know if anyone has ever tried to use client side technology to provide any estimate of the percentage plete. I.e query the servlet processing to get the number of cycles pleted at various point throughout the simulation. This could then be displayed as a bar in the client browser.

Any thoughts, advice, resources would be much appreciated.

Thanks,

Alex

Share Improve this question asked Jun 14, 2010 at 20:16 Alex BarnesAlex Barnes 7,2181 gold badge32 silver badges51 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

In your database, have a table to maintain a list of simulations along with their server-calculated progress.

In your web-application, use AJAX to query the server every few seconds (1-20 depending on load is what I'd go with) and update a graphical progress bar. Most javascript libraries have simple timer-based AJAX functions to do exactly this sort of thing.

There's a few details to figure out, such as whether or not pleted simulations remain in the DB (could be useful logging info), but overall, this should be fairly simple.

You could encapsulate your response in a mime/multipart message and sends your updates until you have a full response done.

Bugzilla uses this in their search to show "Searching ..."-screen until the searchresult is done.

If you want to use plain Struts2, you should take a look at the ExecuteAndWait Interceptor.

It works by the old refresh-with-timeout method. Sure, it has lower coolness factor than some AJAX thing, but it's simple and works (I've used it).

Struts2 takes care (by using this interceptor) of executing the action method (which would typically take a long time) in a separate thread, and it returns a special result wait until the work is pleted. You just have to code a jsp that shows some "waiting..." message for this result, and make it refresh to the same action, repeatedly, with (say) two or three seconds of timeout. The jsp has access to the action properties, of course, hence you can code some getProgress() method to show a progress message or bar.

AJAX is the way to go here.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744109860a4558901.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信