Skip to content

Commit

Permalink
WELD-2755 Avoid "weld-workers" thread group from being created repeat…
Browse files Browse the repository at this point in the history
…edly
  • Loading branch information
TomasHofman committed Sep 15, 2023
1 parent 3a65f62 commit 9d09431
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class AbstractExecutorServices implements ExecutorServices {
private static final long SHUTDOWN_TIMEOUT = 60L;

private final ScheduledExecutorService timerExecutor = Executors.newScheduledThreadPool(1,
new DaemonThreadFactory(new ThreadGroup(DaemonThreadFactory.WELD_WORKERS), "weld-timer-"));
new DaemonThreadFactory(DaemonThreadFactory.ThreadPoolHolder.WELD_WORKERS_THREAD_GROUP, "weld-timer-"));

/**
* Returns a singleton instance of ScheduledExecutorService.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public Thread newThread(Runnable r) {
thread.setDaemon(true);
return thread;
}

// Holder class to postpone thread group creation until when it's needed.
public static class ThreadPoolHolder {
public static final ThreadGroup WELD_WORKERS_THREAD_GROUP = new ThreadGroup(WELD_WORKERS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class FixedThreadPoolExecutorServices extends AbstractExecutorServices {
public FixedThreadPoolExecutorServices(int threadPoolSize) {
this.threadPoolSize = threadPoolSize;
this.executor = Executors.newFixedThreadPool(threadPoolSize,
new DaemonThreadFactory(new ThreadGroup(DaemonThreadFactory.WELD_WORKERS), "weld-worker-"));
new DaemonThreadFactory(DaemonThreadFactory.ThreadPoolHolder.WELD_WORKERS_THREAD_GROUP, "weld-worker-"));
BootstrapLogger.LOG.threadsInUse(threadPoolSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public TimingOutFixedThreadPoolExecutorServices(int threadPoolSize, long keepAli
this.executor = new ThreadPoolExecutor(threadPoolSize, threadPoolSize,
keepAliveTime, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(),
new DaemonThreadFactory(new ThreadGroup(DaemonThreadFactory.WELD_WORKERS), "weld-worker-"));
new DaemonThreadFactory(DaemonThreadFactory.ThreadPoolHolder.WELD_WORKERS_THREAD_GROUP, "weld-worker-"));
// Terminate threads if no new tasks arrive within the keep-alive time
this.executor.allowCoreThreadTimeOut(true);

Expand Down

0 comments on commit 9d09431

Please sign in to comment.