Small correction, 
In your example there is a difference whether you have a multiprocessor
machine. On a single-proc machine it will work fine (prevent second user
from overwriting), on a multi-processor machine it's undefined.

Regards
Leon

> -----Ursprüngliche Nachricht-----
> Von: Durham David R Jr Contr 805 CSPTS/SCE
> [mailto:[EMAIL PROTECTED]
> Gesendet: Dienstag, 14. Dezember 2004 23:46
> An: Struts Users Mailing List
> Betreff: RE: Preventing concurrent execution of an Action
> 
> You might be able to get away with simply adding 'synchronized' to the
> execute method's signature.
> 
> 
>     synchronized public ActionForward execute(...) {
>          updateXml();
>     }
> 
>     private void updateXml() { ... }
> 
> 
> The lock/key threading techniques have to do with, I think, a more
> complex threading issue than the one you've presented.
> 
> 
> - Dave
> 
> 
> > -----Original Message-----
> > From: Behrang Saeedzadeh [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, December 14, 2004 4:34 PM
> > To: [EMAIL PROTECTED]
> > Subject: Preventing concurrent execution of an Action
> >
> > Hi
> >
> > I've an action that creates an XML file on the server. It's executed
> > by clicking on a link. I don't want multiple instances of it to be
> > executed concurrently.
> >
> > Does an approach like the following work?
> >
> > public class UpdateXmlAction ...
> > {
> >        private static final boolean locked;
> >
> >        public void execute(...) {
> >
> >                if (UpdateXmlAction.locked) {
> >                        return;
> >                }
> >
> >                Synchronized(UpdateXmlAction.class) {
> >                        locked = true;
> >                        updateXml();
> >                        locked = false;
> >                }
> >
> >        }
> > }
> >
> > Thanks in advance.
> >
> >
> > --
> >
> > Behrang Saeedzadeh
> > http://www.jroller.com/page/behrangsa
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to