EJB Service Locator with Caching

I use the Locator Service implementation, which caches the result of the call javax.naming.Context#lookupand maps it to the requested EJB interface, so all subsequent requests (for one EJB) will return a caching instance after the first one.

My problems:

  • Since the same instance is used, use an EJB server that will handle multiple simultaneous requests with multiple EJBs (unless the underlying server logic makes use of the EJB pool)
  • Standless and robust EJBs are thread safe, but since, again, only one instance of the EJB class is used, and the EJB has an EntityManager injected through @PersistenceContext, I assume that this means that multiple threads can use the same EntityManager instance (and not just persistence ), which is definitely not thread safe.

Do you think it is better not to use caching in the Service Locator, or that my fears are unjustified regarding the behavior of EJB?

+4
source share
1 answer

What you get from the lookup operation (through the JNDI service) is a Stub object, and it is not fixed using any special EJB instance.

, EJB, EJB ( ); , - EJB .

- .

, , , statefull bean.

EJB - , .


:

EntityManager , , Servlet, , concurrency, EJB Tread Model , , EntityManager , , EM , .

-, , EJB ( @PersistenceContext) EntityManager

, , :

- EntityManager- . ( JPA), EntityManager , . ( ), , .

;)

+5

All Articles