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".

Reply via email to