Search code examples
asynchronousconcurrencysingletonjava-ee-6ejb-3.1

Singletion EJB an Async method (LockType.Write) block till the method processes or will it release lock as soon as it returns the control to client?


I have a singleton EJB(3.1) which is using default container managed concurrency and default (LockType.Write) for all methods, since its not specified explicitly.

I have an Asynchronous method which looks as below:

@Asynchronous
@TransactionAttribute(value = TransactionAttributeType.NOT_SUPPORTED)
@AccessTimeout(-1)
public AsyncResult<Boolean> myAsyncMethod(....){

}

My question is, when invoked, will this method lock the whole singleton bean till the above method completes processing or will it lock only till the time the method returns the Future object to the client ?

Also what effect will "@AccessTimeout(-1)" the on the concurrency of this method/bean.


Solution

  • My question is, when invoked, will this method lock the whole singleton bean till the above method completes processing or will it lock only till the time the method returns the Future object to the client ?

    The singleton bean is never locked at all on the client thread. The client thread schedules the asynchronous method and returns a Future without accessing the bean. The thread that eventually executes the asynchronous method will lock the bean for the duration of the method execution.

    Also what effect will "@AccessTimeout(-1)" the on the concurrency of this method/bean.

    The @AccessTimeout(-1) will cause the thread that eventually attempts to execute the asynchronous method to block until the container-managed lock can be acquired.