1
votes

EJB stateless beans are thread safe in the sense that they can be accessed by many clients at the same time without concerns, in fact each client will be served by a different instance.

On the client side we use proxy references to a particular stateless EJB. Are EJB proxy/remote stubs also thread safe to call?

I mean, if my Spring controller is Autowired with an EJB, its methods will be called possibly by many threads at a time.

Is it all thread safe?

2

2 Answers

2
votes

I asked a similar question about RMI/JRMP stubs some years ago on the RMI mailing list (defunct). The answer from Sun was that there is a presumption that a JDK class is to be considered thread-safe unless the Javadoc states to the contrary.

So assuming that still holds good, which it seems to, the answer is 'yes'. And thinking about client-side connection management, the answer must also be 'yes'.

-1
votes

From http://docs.oracle.com/javaee/6/tutorial/doc/gipjg.html: "When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client but only for the duration of the invocation". This plus the fact that there is a pool of stateless beans (why is there a need to pool stateless objects - one should be enough) indicates that stateless beans are not intrinsically thread safe. It is likely that the EJB container makes sure that concurrent invocations on the "same" bean end up on different pooled instances