Skip to content

Commit

Permalink
WELD-2755 Remove usage of ThreadGroup from Weld executors
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotn committed Sep 26, 2023
1 parent 93e5794 commit 9340b30
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class IncompleteCustomExecutorServices extends AbstractExecutorServices {
static final String PREFIX = "weld-worker-test";

private final transient ExecutorService taskExecutor = Executors
.newSingleThreadExecutor(new DaemonThreadFactory(new ThreadGroup(DaemonThreadFactory.WELD_WORKERS), PREFIX));
.newSingleThreadExecutor(new DaemonThreadFactory(PREFIX));

public ExecutorService getTaskExecutor() {
return taskExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Void call() throws Exception {

public ContainerLifecycleEventPreloader(int threadPoolSize, ObserverNotifier notifier) {
this.executor = Executors.newFixedThreadPool(threadPoolSize,
new DaemonThreadFactory(new ThreadGroup("weld-preloaders"), "weld-preloader-"));
new DaemonThreadFactory("weld-preloader-"));
this.notifier = notifier;
}

Expand Down
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("weld-timer-"));

/**
* Returns a singleton instance of ScheduledExecutorService.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@
*/
public class DaemonThreadFactory implements ThreadFactory {

public static final String WELD_WORKERS = "weld-workers";

private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String threadNamePrefix;
private final ThreadGroup threadGroup;

public DaemonThreadFactory(ThreadGroup threadGroup, String threadNamePrefix) {
this.threadGroup = threadGroup;
public DaemonThreadFactory(String threadNamePrefix) {
this.threadNamePrefix = threadNamePrefix;
}

@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(threadGroup, r, threadNamePrefix + threadNumber.getAndIncrement());
Thread thread = new Thread(r, threadNamePrefix + threadNumber.getAndIncrement());
thread.setDaemon(true);
return thread;
}
Expand Down
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("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("weld-worker-"));
// Terminate threads if no new tasks arrive within the keep-alive time
this.executor.allowCoreThreadTimeOut(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CustomExecutorServices extends AbstractExecutorServices {
static final String PREFIX = "weld-worker-test";

private final transient ExecutorService taskExecutor = Executors
.newSingleThreadExecutor(new DaemonThreadFactory(new ThreadGroup(DaemonThreadFactory.WELD_WORKERS), PREFIX));
.newSingleThreadExecutor(new DaemonThreadFactory(PREFIX));

/**
* Provides access to the executor service used for asynchronous tasks.
Expand Down

0 comments on commit 9340b30

Please sign in to comment.