• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Synchronizing an Action Handler

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Karthik Krishnamurthy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Also my ActionClass extends Action and implements Runnable.
 
reply
    Bookmark Topic Watch Topic
  • New Topic