I have read in "EJB 3 In Action" is that entity manager is not thread safe. In EJB enterprise applications where many session beans use an entity manger reference i suppose that every thread gets its own reference of the entity manager object. My question is there a level of coordination between the entity manager instances. [ August 19, 2007: Message edited by: Khaled Mahmoud ]
I'm not sure if I understand your question, anyway, refering to EntityManager operations take this into account:
There are 3 ways to get a reference to a EntityManager: Injection - JNDI lookup - EJBContext lookup. All of them create a NEW instance of the EntityManager (Injected or looked up), so every instance of the Session or Message Driven Bean get a NEW instance of the EntityManager. (there is no sharing of EntityManagers between components)
There is a special case where the SAME PersistenceContext attached to an EntityManager is propagated and used by two different STATEFUL SESSION BEAN instances. Is the following:
If one Stateful Session Beans with an EXTENDED Persistence Context is the Client of another Session Bean with an EXTENDED Persistence Context, in that case, and ONLY IF BOTH PERSISTENCE CONTEXTS WERE INJECTED, both Statefull Session Bean instances share the same persistence context in the scope of the transaction.
Take a look at the following link to the chapter 7 of Mikalai Zaikin notes and/or numeral 184.108.40.206 (page 122) of the EJB 3 Persistence Specification, where all the Container-Managed Persistence Contexts propagation cases are explained: