Source:
<code>public void stop(final StopContext context) { final ExecutorService executor = executorInjector.getValue(); final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance()); final Runnable task = new Runnable() { @Override public void run() { PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() { @Override public Void run() { if (phaseOnePersistenceUnitServiceInjectedValue.getOptionalValue() != null) { ROOT_LOGGER.stoppingPersistenceUnitService(2, pu.getScopedPersistenceUnitName()); } else { ROOT_LOGGER.stoppingService("Persistence Unit", pu.getScopedPersistenceUnitName()); } ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); if(javaNamespaceSetup != null) { javaNamespaceSetup.setup(Collections.<String, Object>emptyMap()); } <START> final EntityManagerFactory theEntityManagerFactory = entityManagerFactory; <END> try { if (theEntityManagerFactory != null) { synchronized (this) { if (entityManagerFactory != null) { WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName); try { if (theEntityManagerFactory.isOpen()) { theEntityManagerFactory.close(); } } catch (Throwable t) { ROOT_LOGGER.failedToStopPUService(t, pu.getScopedPersistenceUnitName()); } finally { entityManagerFactory = null; pu.setTempClassLoaderFactory(null); WritableServiceBasedNamingStore.popOwner(); persistenceUnitRegistry.remove(getScopedPersistenceUnitName()); } } } } } finally { Thread.currentThread().setContextClassLoader(old); if (javaNamespaceSetup != null) { javaNamespaceSetup.teardown(Collections.<String, Object>emptyMap()); } } final ProxyBeanManager theProxyBeanManager = proxyBeanManager; if (theProxyBeanManager != null) { synchronized (this) { if (proxyBeanManager != null) { theProxyBeanManager.setDelegate(null); proxyBeanManager = null; } } } context.complete(); return null; } }; WildFlySecurityManager.doChecked(privilegedAction, accessControlContext); } }; try { executor.execute(task); } catch (RejectedExecutionException e) { task.run(); } finally { context.asynchronous(); } }</code><technical_language>If double check locking idiom this required</technical_language>

Target:
public void stop(final StopContext context) { final ExecutorService executor = executorInjector.getValue(); final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance()); final Runnable task = new Runnable() { @Override public void run() { PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() { @Override public Void run() { if (phaseOnePersistenceUnitServiceInjectedValue.getOptionalValue() != null) { ROOT_LOGGER.stoppingPersistenceUnitService(2, pu.getScopedPersistenceUnitName()); } else { ROOT_LOGGER.stoppingService("Persistence Unit", pu.getScopedPersistenceUnitName()); } ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); if(javaNamespaceSetup != null) { javaNamespaceSetup.setup(Collections.<String, Object>emptyMap()); } try { if (entityManagerFactory != null) { synchronized (this) { if (entityManagerFactory != null) { WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName); try { if (entityManagerFactory.isOpen()) { entityManagerFactory.close(); } } catch (Throwable t) { ROOT_LOGGER.failedToStopPUService(t, pu.getScopedPersistenceUnitName()); } finally { entityManagerFactory = null; pu.setTempClassLoaderFactory(null); WritableServiceBasedNamingStore.popOwner(); persistenceUnitRegistry.remove(getScopedPersistenceUnitName()); } } } } } finally { Thread.currentThread().setContextClassLoader(old); if (javaNamespaceSetup != null) { javaNamespaceSetup.teardown(Collections.<String, Object>emptyMap()); } } if (proxyBeanManager != null) { synchronized (this) { if (proxyBeanManager != null) { proxyBeanManager.setDelegate(null); proxyBeanManager = null; } } } context.complete(); return null; } }; WildFlySecurityManager.doChecked(privilegedAction, accessControlContext); } }; try { executor.execute(task); } catch (RejectedExecutionException e) { task.run(); } finally { context.asynchronous(); } }