Skip to content

Commit

Permalink
Merge pull request #5672 from TomasHofman/WFCORE-6505
Browse files Browse the repository at this point in the history
WFCORE-6505 Avoid creating duplicate thread groups on server reload
  • Loading branch information
yersan authored Oct 4, 2023
2 parents ef5db71 + 91e07e4 commit 7463a5c
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 18 deletions.
8 changes: 6 additions & 2 deletions cli/src/main/java/org/jboss/as/cli/gui/JConsoleCLIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<JBossThreadFactory>() {
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 ?
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public synchronized void start(StartContext context) throws StartException {

final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
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) {
Expand Down Expand Up @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void recordCapabilitiesAndRequirements(final OperationContext context, R
static ScheduledExecutorService createScannerExecutorService() {
final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {
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);
Expand Down Expand Up @@ -286,4 +286,9 @@ public Set<String> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public void start(StartContext context) throws StartException {
prepareStepHandler.setExecutorService(executorService);
ThreadFactory pingerThreadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
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);
Expand Down Expand Up @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public class HostControllerService implements Service<AsyncFuture<ServiceContain
public static final ServiceName HC_EXECUTOR_SERVICE_NAME = HC_SERVICE_NAME.append("executor");
public static final ServiceName HC_SCHEDULED_EXECUTOR_SERVICE_NAME = HC_SERVICE_NAME.append("scheduled", "executor");

private final ThreadGroup threadGroup = new ThreadGroup("Host Controller Service Threads");
private static final ThreadGroup THREAD_GROUP = new ThreadGroup("Host Controller Service Threads");
private final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public synchronized void start(StartContext context) throws StartException {
try {
final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ServerToHostOperationHandlerFactoryService implements ManagementCha

private final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
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;
Expand Down Expand Up @@ -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");
}
}
10 changes: 7 additions & 3 deletions server/src/main/java/org/jboss/as/server/ServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadFactory>() {
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);
}
});

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void start(StartContext context) throws StartException {
try {
final JBossThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
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);
Expand Down Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class TempFileProviderService implements Service<TempFileProvider> {
try {
final JBossThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
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);
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadFactory>() {
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<Runnable>(256), threadFactory);
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +21,9 @@
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ThreadFactoryService implements Service<ThreadFactory> {

private static final Map<String, ThreadGroup> THREAD_GROUP_CACHE = new ConcurrentHashMap<>();

private String threadGroupName;
private Integer priority;
private String namePattern;
Expand Down Expand Up @@ -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<ThreadFactory>() {
public ThreadFactory run() {
return new JBossThreadFactory(threadGroup, Boolean.FALSE, priority, namePattern, null, null);
Expand Down

0 comments on commit 7463a5c

Please sign in to comment.