I am working on an application that needs to perform some database operations.
I created a static variable for EntityManagerFactory and indexed it in the method that the application calls
if (emf == null){ emf = Persistence.createEntityManagerFactory("example"); } try { em = emf.createEntityManager(); } catch (Exception ex) { logger.error(ex.getMessage()); }
Is this thread safe? if I create an EntityManagerFactory in a synchronized block, the number of pending threads increases and crashes from the application.
I looked through the docs to make sure that Persistence.createEntityManagerFactory is thread safe without any success.
Please indicate me the necessary resources.
java multithreading orm jpa
Vanchinathan chandrasekaran
source share