Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFCORE-6505 Avoid creating duplicate thread groups on server reload #5672

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -187,10 +187,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 @@ -246,4 +245,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 @@ -88,7 +88,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 @@ -161,4 +161,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 @@ -233,7 +233,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 @@ -303,4 +303,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 @@ -540,7 +540,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 @@ -1799,4 +1799,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 @@ -84,10 +84,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 @@ -215,7 +215,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 @@ -83,7 +83,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 @@ -216,4 +216,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 @@ -68,7 +68,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 @@ -123,4 +123,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 @@ -232,11 +232,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 @@ -276,7 +275,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 @@ -694,4 +693,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 @@ -120,7 +120,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 @@ -167,5 +167,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 @@ -52,7 +52,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 @@ -87,4 +87,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 @@ -54,10 +54,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 @@ -115,4 +114,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 @@ -23,6 +23,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 @@ -36,6 +38,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 @@ -67,7 +72,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