最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论