I'd like to know if using entityManagerFactory in a method annotated with @Asynchronous or @schedule is recommanded over the use of an entityManager? From the doc :
While EntityManagerFactory instances are thread-safe, EntityManager instances are not.
So is it mandatory ?
Stateless and stateful EJBs are specified to be thread-safe, so the EJB container is required to ensure that only one method at a time can be used on a bean instance, so you do not need to worry about EntityManager fields of these bean types. For singleton, the default concurrency model is container-managed concurrency with write locks, so you don't need to worry about concurrency of EntityManager fields of those beans unless you change the concurrency settings, and then you might need to consider using EntityManagerFactory.