I support some old JEE code that works fine, but uses some static helper classes in which the entity manager is passed in methods from the calling EJB (s) as follows:
public class StaticHelper { public static void helpingOut(EntityManager entityManager, String value) {
Since this does not seem to be very suitable for JEE and not suitable for unit-test, I converted these helpers to @Stateless EJB as:
@Stateless public class StatelessHelper { @PersistenceContext(unitName="SuperUnit") private EntityManager entityManager; public void helpingOut(String value) {
Similarly, I can insert a mocking helper in the calling EJB with the CDI-Unit .
Now, depending on the load, 1-3 instances of this helper without saving are created by the container, which is not a problem at all, I would say, but in any case I was thinking about @Singleton using either @ConcurrencyManagement(ConcurrencyManagementType.BEAN) or @Lock(LockType.READ) to make it multithreaded, but this does not seem to be a good idea, since EntityManager not thread safe. Or is the explanation here still applied?
"... A container serializes calls for each state and an idle session bean instance. Most containers will support many bean sessions at the same time; 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 ... "
source share