code: @Override
      public final void close()
      {
          if (isOpen())
          {
              closed = true;
  
              // Shut cache provider down
              if (cacheProvider != null)
              {
                  cacheProvider.shutdown();
              }
  
              for (String pu : persistenceUnits)
              {
                  ((ClientLifeCycleManager) clientFactories.get(pu)).destroy();
              }
              this.persistenceUnits = null;
              this.properties = null;
              clientFactories.clear();
              clientFactories = new ConcurrentHashMap<String, ClientFactory>();
          }
          else
          {
              throw new IllegalStateException("Entity manager factory has been closed");
          }
      }
docs: Close the factory, releasing any resources that it holds. After a factory
  instance has been closed, all methods invoked on it will throw the
  IllegalStateException, except for isOpen, which will return false. Once
  an EntityManagerFactory has been closed, all its entity managers are
  considered to be in the closed state.
  
  @throws IllegalStateException
  if the entity manager factory has been closed
  @see javax.persistence.EntityManagerFactory#close()