posted 19 years ago
Hi,
I am writing an application which needs my action handler to be synchronized.
I tried the following:
************************************************************
static boolean anotherInstanceRunning = false;
public synchronized ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException,SQLException,ClassNotFoundException {
while (anotherInstanceRunning) {
try{
System.out.println("Waiting....");
wait();
} catch (InterruptedException ie) {
System.out.println("INTERRUPTED!!!");
}
}
anotherInstanceRunning = true;
.....................
<finish processing>
anotherInstanceRunning = false;
notifyAll();
return mapping.findForward(...)
**************************************************
The problem comes when two instances access the handler at almost the same time, then the lock is not being obtained since anotherInstanceRunning seems to be false for both instances.
Any ideas how I can incorporate this. Its very important for my application.
Thanks
Karthik