3. Singleton Beans - JohnyzHub/EJB3x GitHub Wiki
Stateless Session Bean
Concurrency management makes sense only on singleton beans, as the same object is shared by multiple clients.-
Container Managed Concurrency(default) – Container controls the concurrent access
@Lock(LockType.READ/WRITE) – Specifies how the container must manage the concurrency when client invokes a method call. Lock can be applied at method level and or class level.
WRITE(Default) - It is worth remembering that when a thread makes a call to this method, it locks not only that method but also the whole bean class and other threads trying to access this bean (irrespecive of which method) will be kept on wait until the the current thread finish its process or the set timeout is reached whichever occurs first.
READ - Read allows multiple clients(threads) to access the method, provided some other thread has not already locked the whole bean for writing(Lock.Write). Read means no concurrency applied.
Check official doc: Concurrent Access in a Singleton Session Bean -
Bean Managed Concurrency – Bean is responsible to control concurrent access to methods.
Value = 0: Concurrent access not permitted.
- -1: Request will be blocked indefinitely until gets access.
- >0: Time out value (Unit of type of java.util.concurrent.TimeUnit)
Please note that this annotation may be used to singleton bean with container managed concurrency or the stateful bean, to control the access time.