Carl,
The problem that you describe is real, and there are different solutions
depending on how restrictive you want to make the updates. I prefer
optimistic updates for most programs that I develop.
With that said, make Club your entity bean and mark the addMember() method
as RequiresTransaction. Whether you access the entity bean directly, or
through a session bean, it will be part of a transaction. As I understand
it, this entity bean can only participate in one transaction at a time. In
the addMember() method, add the call to roomForMember().
jim
----- Original Message -----
From: Carl Jones <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, May 07, 1999 10:58 AM
Subject: EJBs and Synchronisation
> Hi,
>
> I've just read Mike Mannion's article on "Concurrent Contracts"
> in JavaReport (May 1999). One section of the article talks about
> "Command Query Separation" or CQS, where methods are designed to either
> be commands or queries but never both.
>
> The example given is..
>
> 1 if (club.roomForMember())
> 2 club.newMember(m);
> 3 else
> 4 System.out.println("Membership Exceeded");
>
> The problem in a concurrent situation is that between lines 2 & 4, another
> client could call newMember() and grab the last place.
>
> The solution proposed is to use synchronized thus
>
> 1 synchronized(club)
> 2 {if (club.roomForMember())
> 3 club.newMember(m);
> 4 else
> 5 System.out.println("Membership Exceeded");
> 6 }
>
> However, in the EJB specification (March 21, 1998), it says (section
16.4),
> "An Enterprise Bean is not allowed to use thread synchronization
primatives".
>
>
> So, if I have a SessionBean calling an EntityBean, does this mean that my
> SessionBean can't use the above solution?
>
> If this is the case, one solution is to combine the check and the update
> into one method on the EntityBean, but this goes against CQS and
> the greater principle of design by contract.
>
> Any comments or ideas greatly appreciated.
>
> Thanks.
>
> Carl Jones
> BT
>
> (All opinions are my own and they might be different to employers)
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".