Ejb thread security: do we need this?

Consider Standing EJB

from ejb 3.1 spec
containers will support many instances of a
bean session running simultaneously; however, each instance only sees a serialized sequence of method calls. Therefore, a state or session without a bean should not be encoded as reentrant

Thus, membership without a bean can "serve" no more than one request at a time, this is usually implemented by the container that manages the beans pool. A great goal is thread safety.

My question is: why do we need this form of thread safety? I mean, Spring beans are single point and non-thread safe (they can serve any number of requests at a time), and we have no problem with this.

+4
source share
1 answer

You need this form of thread safety if a non-bean session has member variables that are not thread safe by themselves (like SAXParser). However, since a session without a beans state does not have a client proximity like a session with a beans state, use cases are admittedly relatively rare, and the servlet programming model seems to have shown that this level of protection is probably not needed. therefore, if you do not need thread safety, and with EJB 3.1 you can use a singleton bean session with bean -managed concurrency.

EJB- . , EJB , bean, / , ThreadLocal ( , UserTransaction SessionContext).

+4

Source: https://habr.com/ru/post/1628712/


All Articles