开发者

Show progress of running java process, even after reopening webpage

开发者 https://www.devze.com 2023-02-09 16:52 出处:网络
I am working for a company developing web based software J2EE. On our webapp its possible to upload a csv file. Ive got some kind of 开发者_Go百科reader class which reads each line and processes it.

I am working for a company developing web based software J2EE.

On our webapp its possible to upload a csv file. Ive got some kind of 开发者_Go百科reader class which reads each line and processes it. (It checks if the values in each csv line are valid and inserts them into the database). Along with this the reader counts the lines read to show this number at the end of the process.

Users can upload a file and click on the 'process' button, after this the process starts. But these processes can have a very long duration since the csv files can be very big. When the users closes the webbrowser the process still continues on the server.

I want users to let them follow the progress. Even when they close the browser and log in again. So I guess there should be some kind of ID attached to each process, to know which user's process it is and what the status of the progress is?

Is there some kind of mechanism in Java with which I can accomplish this?


The simplest way to track the progress is to get the process to write its update to a database table - say 'jobs'. When a user uploads a new csv file and hits 'process', you can first make an entry into this table. The process periodically writes to the table its progress. When the user logs in to his account he can see all the jobs he had started and their progress. This is not the cleanest approach but it will get the work done. A lot of things depend on your specific framework. Perhaps you could make an entry into this table with the process id and there wont be a need for you to update the progress in the table. The frontend could then use a RPC to your process to query its progress.


If you store the csv as raw in a table in the database the entry should have a unique UPLOAD_ID. There should be another column in that table to reference the associated CLIENT as a foreign key. In short you need to associate the uploaded entry with the client or username of that client that performed the upload.

0

精彩评论

暂无评论...
验证码 换一张
取 消