Skip to content

Commit

Permalink
WFCORE-6505 Avoid creating duplicate thread groups on server reload
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasHofman committed Sep 20, 2023
1 parent ef07287 commit 0ca20b8
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
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(null, Boolean.FALSE, null, "management-client-thread " + executorCount.incrementAndGet() + "-%t", null, null);
}
});
return EnhancedQueueExecutor.DISABLE_HINT ?
Expand Down
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(null, Boolean.FALSE, null, "management-handler-thread - %t", null, null);
}
});
if (EnhancedQueueExecutor.DISABLE_HINT) {
Expand Down
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(null, Boolean.FALSE, null, "DeploymentScanner-threads - %t", null, null);
}
});
return Executors.newScheduledThreadPool(2, threadFactory);
Expand Down
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(null, Boolean.TRUE, null, "proxy-pinger-threads - %t", null, null);
}
});
pingScheduler = Executors.newScheduledThreadPool(PINGER_POOL_SIZE, pingerThreadFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ 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 final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
public JBossThreadFactory run() {
return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, "%G - %t", null, null);
return new JBossThreadFactory(null, Boolean.FALSE, null, "Host Controller Service Threads - %t", null, null);
}
});
private final HostControllerEnvironment environment;
Expand Down Expand Up @@ -215,7 +214,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, null);
}

@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(null, Boolean.FALSE, null, "ProcessControllerConnection-thread - %t", null, null);
}
});
final ExecutorService executorService;
Expand Down
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(null, Boolean.FALSE, null, "server-registration-threads - %t", null, null);
}
});
private volatile ExecutorService registrations;
Expand Down
5 changes: 2 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(null, 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, null, EXECUTOR_CAPABILITY.getCapabilityServiceName());
}

public synchronized void start(final StartContext context) throws StartException {
Expand Down
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(null, true, null, "ServerDeploymentRepository-temp-threads - %t", null, null);
}
});
scheduledExecutorService = Executors.newScheduledThreadPool(2, threadFactory);
Expand Down
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(null, Boolean.TRUE, null, "TempFileProviderService-temp-threads - %t", null, null);
}
});
ScheduledThreadPoolExecutor ex = new ScheduledThreadPoolExecutor(0, threadFactory);
Expand Down
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(null, Boolean.FALSE, null, "domain-mgmt-client-thread " + executorCount.incrementAndGet() + "-%t", null, null);
}
});
return new ThreadPoolExecutor(4, 4, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(256), threadFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ private ServiceName resolveDefaultThreadFactory(String threadPoolName, ServiceNa
ServiceTarget serviceTarget) {
final ServiceName threadFactoryServiceName = threadPoolServiceName.append("thread-factory");
final ThreadFactoryService service = new ThreadFactoryService();
service.setThreadGroupName(getThreadGroupName(threadPoolName));
service.setNamePattern("%G - %t");

// Do not set service#threadGroupName, make the group name part of the pattern instead. Setting the
// service#threadGroupName would lead to a ThreadGroup being created each time the service is restarted.
String threadGroupName = getThreadGroupName(threadPoolName);
service.setNamePattern(threadGroupName + " - %t");

serviceTarget.addService(threadFactoryServiceName, service).install();
return threadFactoryServiceName;
}
Expand Down

0 comments on commit 0ca20b8

Please sign in to comment.