with improved connection (EntityManager) locking and shut down hook