tags:

views:

92

answers:

5

My requirements are as follows.

I have a web application developed in java.

I have a link in the html page. When the first client clicks submit button in the html page the batch file should run.

Meanwhile when the other client clicks the submit button he should get message that the page is busy.

If the first client clicks release button then the other clients must be able to run the batch file.

How can I do that?

+1  A: 

Set a flag when the submit button is clicked and clear it when the release button is clicked.

Depending on your architecture, the flag can be anything from a boolean variable in your code, a special entry somewhere in your database to a temporary file.

When the submit button is clicked, check whether the flag is already set. When it is, return an error message stating that the page is busy.

In pseudo code:

if (flagIsSet()) {
  showPageIsBusy();
} else {
  setFlag();
  startBatchFile();
}

Remember to clear the flag when the batch file finishes or the release button is clicked and somewhere in a finally block.

You also have to make sure that only the client who started the batch file can release it and clear the flag.

As pointed out by Avi in the comments, you should also remember to synchronize access to the flag.

gclj5
As long as you remember to synchronize access to the flag. And make sure to clear it in a finally block, so that it doesn't get stuck.
Avi
That's true. I added those points to my answer so that they are more visible.
gclj5
A: 

Pseudo algorithm:

Modify the batch file to run a servlet before and after batch operations.

Before running batch file, set a servlet or flag that will register a file or database or a session variable that I am being executed and at completion of batch file, set a servlet or flag that will register a file or database or a session variable that I am being released

When user clicks release button, run the same servlet which will relase the flag.

When User submits submit button, check for that flag whether it is executed or released, depending upon you alert your client.

lakshmanaraj
A: 

you could use a field in servlet class (a big nono otherwise) for a flag.

miceuz
A: 

If your application happens to run on multiple load-balanced servers, then you face the same problem I do :) I submitted a question earlier about it, but unfortunately I didn't get any response. In any case, you can see my solution for the problem as an answer to my question here.

mitchnull
A: 

That is a Singleton or better an Application-Bean. This Bean should kick of your long running background task and provide information about it, e.g. if it is running and maybe stuff like when did it start, who started it and if you could the progress, so you could display a progress bar as well.

If you would tell us, what web application framework you use, we could give better tips, I think.

Tim Büthe