tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Louis MONTEIRO <jean-louis.monte...@atosorigin.com>
Subject Re: General approach for locking entities
Date Tue, 02 Feb 2010 17:49:09 GMT

Hi, 

David is probably the best guy to help on that topic.
Anyway, there is no absolute rule.
Pessimistic locking works but is bad for concurrency.
Optimistic is better for concurrency.


Karsten Ohme-3 wrote:
> 
> Pro: concurrency is maximum
> Con: I have to run a separate transaction to catch the
> OptimisticLockingException and transform it into an application
> exception, to let the user know that he has to try again.
> 

Not required. 
If you wait until the end of the transaction, the caller will receive an
EJBException not an OptimisticLockingException. According to the spec
(AFAIK), the container is not required to provide the surrounding exception
in the root cause.

When using optimistic locking, i just call the em.flush() method in my
business method (in a stateless for example). So, you are free to catch the
OptimisticLockingException and throw a business exception (checked and
declared in the throws - or - Runtime + @ApplicationException).

Hope it helps,
Jean-Louis

-- 
View this message in context: http://n4.nabble.com/General-approach-for-locking-entities-tp1460076p1460160.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Mime
View raw message