Meaningless Drivel is fun!
The moose likes Servlets and the fly likes Servlets and synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets and synchronized" Watch "Servlets and synchronized" New topic

Servlets and synchronized

Paul Richards

Joined: Jul 25, 2001
Posts: 19
I have a problem where the user may press the submit button button and submit the form to a servlet.
Within the servlet a call to a AS400 stored procedure is made, which in several circumstances may take time to execute.
Whilst this execution is taking place the user may press the submit button again thus possibly calling the AS400 stored procedure agian before the previous one has finished.
This is a situation I need to prevent.
Would putting a
synchronized (request.getSession){
.....as400 call....
prevent this problem?
cheers for any advice.
Sunetra Saha
Ranch Hand

Joined: Feb 25, 2001
Posts: 77
I don't think you can do this by synchronizing. Why not just set a flag in the servlet before calling the procedure and reset it after the procedure finishes? Then just a check on the flag can prevent multiple procedure calls even if the submit button is pressed repeatedly.
Or maybe you can try javascript to prevent resubmission of the form.
Aman Rustogi

Joined: May 11, 2001
Posts: 22
I agree with Sunitra. A workaround solution would be to either set a timer [using javascript] to - ummm say sumthing 'round 2 mins. before again submitting the request/calling the servlet which calls the procedure. It would thus prevent the user from submitting the form till the time set expires.
I agree. Here's the link:
subject: Servlets and synchronized
jQuery in Action, 3rd edition