diff --git a/cli/src/main/java/org/jboss/as/cli/gui/JConsoleCLIPlugin.java b/cli/src/main/java/org/jboss/as/cli/gui/JConsoleCLIPlugin.java index 4fa873d9947..dc1a77e88cb 100644 --- a/cli/src/main/java/org/jboss/as/cli/gui/JConsoleCLIPlugin.java +++ b/cli/src/main/java/org/jboss/as/cli/gui/JConsoleCLIPlugin.java @@ -173,10 +173,9 @@ private boolean connectUsingRemoting(CommandContext cmdCtx, RemotingMBeanServerC } private ExecutorService createExecutor() { - final ThreadGroup group = new ThreadGroup("management-client-thread"); final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public JBossThreadFactory run() { - return new JBossThreadFactory(group, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null); } }); return EnhancedQueueExecutor.DISABLE_HINT ? @@ -232,4 +231,9 @@ private void configureMyJInternalFrame() { } } } + + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("management-client-thread"); + } } \ No newline at end of file diff --git a/controller/src/main/java/org/jboss/as/controller/remote/AbstractModelControllerOperationHandlerFactoryService.java b/controller/src/main/java/org/jboss/as/controller/remote/AbstractModelControllerOperationHandlerFactoryService.java index c3a8f1f09d0..23f4a843595 100644 --- a/controller/src/main/java/org/jboss/as/controller/remote/AbstractModelControllerOperationHandlerFactoryService.java +++ b/controller/src/main/java/org/jboss/as/controller/remote/AbstractModelControllerOperationHandlerFactoryService.java @@ -71,7 +71,7 @@ public synchronized void start(StartContext context) throws StartException { final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public JBossThreadFactory run() { - return new JBossThreadFactory(new ThreadGroup("management-handler-thread"), Boolean.FALSE, null, "%G - %t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.FALSE, null, "%G - %t", null, null); } }); if (EnhancedQueueExecutor.DISABLE_HINT) { @@ -144,4 +144,9 @@ protected final ExecutorService getClientRequestExecutor() { return clientRequestExecutor; } + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("management-handler-thread"); + } + } diff --git a/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/DeploymentScannerAdd.java b/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/DeploymentScannerAdd.java index cf74baf780f..dc696608f87 100644 --- a/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/DeploymentScannerAdd.java +++ b/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/DeploymentScannerAdd.java @@ -216,7 +216,7 @@ private void recordCapabilitiesAndRequirements(final OperationContext context, R static ScheduledExecutorService createScannerExecutorService() { final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public ThreadFactory run() { - return new JBossThreadFactory(new ThreadGroup("DeploymentScanner-threads"), Boolean.FALSE, null, "%G - %t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.FALSE, null, "%G - %t", null, null); } }); return Executors.newScheduledThreadPool(2, threadFactory); @@ -286,4 +286,9 @@ public Set getUnrelatedDeployments(ModelNode owner) { return Collections.emptySet(); } } + + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("DeploymentScanner-threads"); + } } diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java b/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java index 701f6a0a273..128598a2b26 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java @@ -523,7 +523,7 @@ public void start(StartContext context) throws StartException { prepareStepHandler.setExecutorService(executorService); ThreadFactory pingerThreadFactory = doPrivileged(new PrivilegedAction() { public JBossThreadFactory run() { - return new JBossThreadFactory(new ThreadGroup("proxy-pinger-threads"), Boolean.TRUE, null, "%G - %t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.TRUE, null, "%G - %t", null, null); } }); pingScheduler = Executors.newScheduledThreadPool(PINGER_POOL_SIZE, pingerThreadFactory); @@ -1782,4 +1782,10 @@ public void propertyChange(PropertyChangeEvent evt) { } } } + + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("proxy-pinger-threads"); + } + } diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java index 7f3dd503b47..493d20b02a9 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerService.java @@ -67,10 +67,10 @@ public class HostControllerService implements Service() { public JBossThreadFactory run() { - return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, "%G - %t", null, null); + return new JBossThreadFactory(THREAD_GROUP, Boolean.FALSE, null, "%G - %t", null, null); } }); private final HostControllerEnvironment environment; @@ -198,7 +198,7 @@ public void start(StartContext context) throws StartException { ConsoleAvailabilityService.addService(serviceTarget, bootstrapListener::logAdminConsole); DomainModelControllerService.addService(serviceTarget, environment, runningModeControl, processState, - bootstrapListener, hostPathManagerService, capabilityRegistry, threadGroup); + bootstrapListener, hostPathManagerService, capabilityRegistry, THREAD_GROUP); } @Override diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/ProcessControllerConnectionService.java b/host-controller/src/main/java/org/jboss/as/host/controller/ProcessControllerConnectionService.java index dcd4b1fa3dd..d10b1bf2970 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/ProcessControllerConnectionService.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/ProcessControllerConnectionService.java @@ -66,7 +66,7 @@ public synchronized void start(StartContext context) throws StartException { try { final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public JBossThreadFactory run() { - return new JBossThreadFactory(new ThreadGroup("ProcessControllerConnection-thread"), Boolean.FALSE, null, "%G - %t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.FALSE, null, "%G - %t", null, null); } }); final ExecutorService executorService; @@ -199,4 +199,8 @@ public synchronized ProcessControllerClient getClient() throws IllegalStateExcep return client; } + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("ProcessControllerConnection-thread"); + } } diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/mgmt/ServerToHostOperationHandlerFactoryService.java b/host-controller/src/main/java/org/jboss/as/host/controller/mgmt/ServerToHostOperationHandlerFactoryService.java index 2dac74b118e..72cd5892d6a 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/mgmt/ServerToHostOperationHandlerFactoryService.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/mgmt/ServerToHostOperationHandlerFactoryService.java @@ -51,7 +51,7 @@ public class ServerToHostOperationHandlerFactoryService implements ManagementCha private final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public JBossThreadFactory run() { - return new JBossThreadFactory(new ThreadGroup("server-registration-threads"), Boolean.FALSE, null, "%G - %t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.FALSE, null, "%G - %t", null, null); } }); private volatile ExecutorService registrations; @@ -106,4 +106,8 @@ public ManagementChannelHandler startReceiving(final Channel channel) { return channelHandler; } + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("server-registration-threads"); + } } diff --git a/server/src/main/java/org/jboss/as/server/ServerService.java b/server/src/main/java/org/jboss/as/server/ServerService.java index 9aa82e2d4ee..9bc9236a413 100644 --- a/server/src/main/java/org/jboss/as/server/ServerService.java +++ b/server/src/main/java/org/jboss/as/server/ServerService.java @@ -215,11 +215,10 @@ public static void addService(final ServiceTarget serviceTarget, final Bootstrap final SuspendController suspendController) { // Install Executor services - final ThreadGroup threadGroup = new ThreadGroup("ServerService ThreadGroup"); final String namePattern = "ServerService Thread Pool -- %t"; final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public ThreadFactory run() { - return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.FALSE, null, namePattern, null, null); } }); @@ -259,7 +258,7 @@ public ThreadFactory run() { serviceBuilder.install(); - ExternalManagementRequestExecutor.install(serviceTarget, threadGroup, EXECUTOR_CAPABILITY.getCapabilityServiceName()); + ExternalManagementRequestExecutor.install(serviceTarget, ThreadGroupHolder.THREAD_GROUP, EXECUTOR_CAPABILITY.getCapabilityServiceName()); } public synchronized void start(final StartContext context) throws StartException { @@ -677,4 +676,9 @@ public synchronized ScheduledExecutorService getValue() throws IllegalStateExcep return scheduledExecutorService; } } + + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("ServerService ThreadGroup"); + } } diff --git a/server/src/main/java/org/jboss/as/server/deployment/DeploymentMountProvider.java b/server/src/main/java/org/jboss/as/server/deployment/DeploymentMountProvider.java index 31c67cbc73d..6a4013d4708 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/DeploymentMountProvider.java +++ b/server/src/main/java/org/jboss/as/server/deployment/DeploymentMountProvider.java @@ -103,7 +103,7 @@ public void start(StartContext context) throws StartException { try { final JBossThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public JBossThreadFactory run() { - return new JBossThreadFactory(new ThreadGroup("ServerDeploymentRepository-temp-threads"), true, null, "%G - %t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, true, null, "%G - %t", null, null); } }); scheduledExecutorService = Executors.newScheduledThreadPool(2, threadFactory); @@ -150,5 +150,10 @@ public void run() { } } + + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("ServerDeploymentRepository-temp-threads"); + } } } diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/TempFileProviderService.java b/server/src/main/java/org/jboss/as/server/deployment/module/TempFileProviderService.java index bd7d301acea..601e71bf1ee 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/TempFileProviderService.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/TempFileProviderService.java @@ -35,7 +35,7 @@ public class TempFileProviderService implements Service { try { final JBossThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public JBossThreadFactory run() { - return new JBossThreadFactory(new ThreadGroup("TempFileProviderService-temp-threads"), Boolean.TRUE, null, "%G - %t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.TRUE, null, "%G - %t", null, null); } }); ScheduledThreadPoolExecutor ex = new ScheduledThreadPoolExecutor(0, threadFactory); @@ -70,4 +70,9 @@ public TempFileProvider getValue() throws IllegalStateException { public static TempFileProvider provider() { return PROVIDER; } + + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("TempFileProviderService-temp-threads"); + } } diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/integration/domain/management/util/DomainControllerClientConfig.java b/testsuite/shared/src/main/java/org/jboss/as/test/integration/domain/management/util/DomainControllerClientConfig.java index d382c709b46..25f70cccf9e 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/integration/domain/management/util/DomainControllerClientConfig.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/integration/domain/management/util/DomainControllerClientConfig.java @@ -37,10 +37,9 @@ public class DomainControllerClientConfig implements Closeable { private static final AtomicInteger executorCount = new AtomicInteger(); static ExecutorService createDefaultExecutor() { - final ThreadGroup group = new ThreadGroup("domain-mgmt-client-thread"); final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction() { public ThreadFactory run() { - return new JBossThreadFactory(group, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null); + return new JBossThreadFactory(ThreadGroupHolder.THREAD_GROUP, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null); } }); return new ThreadPoolExecutor(4, 4, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue(256), threadFactory); @@ -98,4 +97,8 @@ static DomainControllerClientConfig create(final ExecutorService executorService return new DomainControllerClientConfig(endpoint, executorService, destroyExecutor); } + // Wrapper class to delay thread group creation until when it's needed. + private static class ThreadGroupHolder { + private static final ThreadGroup THREAD_GROUP = new ThreadGroup("domain-mgmt-client-thread"); + } } diff --git a/threads/src/main/java/org/jboss/as/threads/ThreadFactoryService.java b/threads/src/main/java/org/jboss/as/threads/ThreadFactoryService.java index 881f6002df6..3d001bda07a 100644 --- a/threads/src/main/java/org/jboss/as/threads/ThreadFactoryService.java +++ b/threads/src/main/java/org/jboss/as/threads/ThreadFactoryService.java @@ -6,6 +6,8 @@ package org.jboss.as.threads; import java.security.PrivilegedAction; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadFactory; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; @@ -19,6 +21,9 @@ * @author David M. Lloyd */ public final class ThreadFactoryService implements Service { + + private static final Map THREAD_GROUP_CACHE = new ConcurrentHashMap<>(); + private String threadGroupName; private Integer priority; private String namePattern; @@ -50,7 +55,8 @@ public synchronized void setNamePattern(final String namePattern) { @Override public synchronized void start(final StartContext context) throws StartException { - final ThreadGroup threadGroup = (threadGroupName != null) ? new ThreadGroup(threadGroupName) : null; + final ThreadGroup threadGroup = THREAD_GROUP_CACHE.computeIfAbsent(threadGroupName, name -> + name != null ? new ThreadGroup(name) : null); value = doPrivileged(new PrivilegedAction() { public ThreadFactory run() { return new JBossThreadFactory(threadGroup, Boolean.FALSE, priority, namePattern, null, null);