Concurrent access Stateless Sessionbean from Singleton

244 views Asked by At

If my understanding is correct, the container does not make concurrent calls to an SLSB. Calls are serialized or a new SLSB instance is created. My questions are:

Is it safe to access the SLSB from a singletion which has ConcurrencyManagement.BEAN, where concurrent calls can happen?

And if it is safe, is it also safe to use an entitymanager instance inside the SLSB, because entitymanager is not thread safe and if the SLSB instance is shared between different threads, the entitymanager is also shared between the threads.

Thanks in advance!

1

There are 1 answers

0
user3714601 On BEST ANSWER

Yes for both questions, it's safe. One session bean, stateless or stateful could be used by only one thread at a time.

From EJB 3.1 specification:

The container must ensure that only one thread can be executing a stateless or stateful session bean instance at any time.

http://download.oracle.com/otndocs/jcp/ejb-3.1-pfd-oth-JSpec/

In case 2 concurrent calls come from your singleton, these will be served by 2 different instances of SLSB.