title: How to create a thread safe EntityManagerFactory?
body: <p>I'm working on an application that needs to do some database operations.</p>
  
  <p>I created a static variable for <code>EntityManagerFactory</code> and initializeded it in the method that gets called by the application</p>
  
  <pre><code> if (emf == null) {
        emf = Persistence.createEntityManagerFactory("example");
   }
  
   try {
        em = emf.createEntityManager();
   } catch (Exception ex) {
        logger.error(ex.getMessage());
   }
  </code></pre>
  
  <p>Is this thread-safe? If I create the <code>EntityManagerFactory</code> in a synchronized block, the number of the waiting threads increases and crashes the application.</p>
  
  <p>I looked at the docs to see whether the <code>Persistence.createEntityManagerFactory</code> is thread-safe without any success.</p>
  
  <p>Please direct me to the right resources.</p>