Greetings,

Someone who is less of a newbie could maybe give a more definitive answer,
but I think this is the situation:

This is to prevent an infinite loop if two objects have references to each
other.  The first will call the save code for the other, which will call the
save code for the first.  Using 'synchronized' is insufficient in this case,
because 'sychronized' only prevents OTHER threads from executing the same
code.

I've got a sneaky suspicion that this situation shouldn't arise in a
well-defined database schema, but it may be more common than I think, and at
any rate, I know I need protected from myself sometimes.

-Brent

----- Original Message -----
From: "Jason Kary" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, July 30, 2001 6:24 AM
Subject: Re: A question in BaseXXXPeer


> If this is the case then why would a person not use 'synchronized'?
>
> Take Care
> Jason Kary
>
>
> Bartek Walter wrote:
>
> > jb> This is part of source code of BaseXXX
> >
> > jb> ...
> > jb>     public void save(DBConnection dbCon) throws Exception
> > jb>     {
> > jb>         if (!alreadyInSave)
> > jb>       {
> > jb>         alreadyInSave = true;
> > jb>           if (isModified())
> > jb>         {
> > jb>             if (isNew())
> > jb>             {
> > jb>                 XXXPeer.doInsert((XXX)this, dbCon);
> > jb>                 setNew(false);
> > jb>             }
> > jb>             else
> > jb>             {
> > jb>                 XXXPeer.doUpdate((XXX)this, dbCon);
> > jb>             }
> > jb>         }
> > jb>               alreadyInSave = false; // Why this line? It's just
saved, right?
> > jb>       }
> > jb>    }
> > jb> ...
> >
> > it is a kind of a semaphore, I think, in order to avoid race
> > conditions when saving the same object concurrently.
> > This method is not synchronized probably for efficiency purposes, so
> > the semaphore does the job.
> >
> > Regards,
> > -Bartek Walter
> >
> > ---------------------------------------------------------------------
> > 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