当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Showing calculation progress real time and retain progress even if the browser is closed

问题描述:

Suppose, this is in any jsp with servlet project.

I clicked a button to calculate something, and the process will be done in a few steps or by using some synchronized threads that need nearly 5 hours.

If I close the browser window after a click, what will happen?

Will the calculation process stop or continue?

If its the latter (continue), and I log in to my account after 2 hours, what will I see?

I want to see the calculation progress real time.

What should i do?

网友答案:

This kind of processing requires planning. There are many edge cases. What if the process is already running? What to do if the server terminates in the middle of processing? Can you restart? Can the processing be interrupted? Can every user start this processing, or just authorized ones?

Ok, now to an answer. You want to run the processing in a separate, background thread. See the Executor classes. Then you have to store the progress of that processing somewhere (think db here) and create another page to show that progress. You may also have to remember the user that started the processing, so that you know which of the progress information to show to the user requesting the progress.

So, simple! :)

分享给朋友:
您可能感兴趣的文章:
随机阅读: