File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets and synchronized" Watch "Servlets and synchronized" New topic
Author

Servlets and synchronized

Paul Richards
Greenhorn

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.
Paul
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
Greenhorn

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.
cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets and synchronized