I'm working on a application that needs to do some database operations.
I created a static variable for EntityManagerFactory and Intialized it in the method that gets called by the application
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 the EntityManagerFactory in a synchronized block, The number of waiting threads increases and crashes the application.
I looked at the docs to see whether the Persistence.createEntityManagerFactory is thread safe without any success.
Please point me to the right resources.