Reputation: 21329
There is a heavy database process that has to be executed before loading the jsp.
// jsp
<% new bean().startHeavyProcess(); %>
.
.
.
As the process is going,I want to show a progress bar
using java script
. Is there any way I can make the progress bar work in synchronization with the server side code ? Can I know when the server side code finishes its execution or is about to finish the execution ?
Upvotes: 0
Views: 1403
Reputation: 6880
Without you building functionality to achieve this specific to your application there is no way of doing this.
I'm assuming the heavy processing is initiated by the client clicking on a link?
If so then you could try the following.
This approach requires that you have some sort of Heavy Process Manager that has a knowledge of all running processes and can extract a process from these..
This could perhaps be done by creating a new Table in your database in which you store the process unique id and the % progress of each process. Each of the processes then update their row in the table as they progress and you simply return the progression value from the table when requested by its ID.
If your looking for a good progress bar plugin Jquery has it: http://jqueryui.com/progressbar/ :)
Upvotes: 2
Reputation: 385
We had a similar use case, and we implemented by checking the status periodically using the REST API. When the task is in progress in server side, server updates the status in memory and client requests for the progress from API.
Upvotes: 1
Reputation: 616
I did this by using
function pollProgress() {
setTimeout(function() {
int progress = queryServerProgress();
if(progress < 100) {
pollProgress();
}
}, 1000)
}
and querying the server of the current progress. Triggering the same query/update function as long as the progress is < 100%.
You need to keep track of the progress on the server side though.
Upvotes: 1