From 9340b30e358ef42560496b99d0ef2fab6a26432d Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Mon, 18 Sep 2023 15:25:57 +0200 Subject: [PATCH] WELD-2755 Remove usage of ThreadGroup from Weld executors --- .../options/timeout/IncompleteCustomExecutorServices.java | 2 +- .../events/ContainerLifecycleEventPreloader.java | 2 +- .../org/jboss/weld/executor/AbstractExecutorServices.java | 2 +- .../java/org/jboss/weld/executor/DaemonThreadFactory.java | 8 ++------ .../weld/executor/FixedThreadPoolExecutorServices.java | 2 +- .../TimingOutFixedThreadPoolExecutorServices.java | 2 +- .../tests/event/async/stage/CustomExecutorServices.java | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/environments/se/tests/src/test/java/org/jboss/weld/environment/se/test/event/options/timeout/IncompleteCustomExecutorServices.java b/environments/se/tests/src/test/java/org/jboss/weld/environment/se/test/event/options/timeout/IncompleteCustomExecutorServices.java index 7a0a5da930d..7cb3e6b7d97 100644 --- a/environments/se/tests/src/test/java/org/jboss/weld/environment/se/test/event/options/timeout/IncompleteCustomExecutorServices.java +++ b/environments/se/tests/src/test/java/org/jboss/weld/environment/se/test/event/options/timeout/IncompleteCustomExecutorServices.java @@ -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; diff --git a/impl/src/main/java/org/jboss/weld/bootstrap/events/ContainerLifecycleEventPreloader.java b/impl/src/main/java/org/jboss/weld/bootstrap/events/ContainerLifecycleEventPreloader.java index f0e8ba46e0b..fc2124af888 100644 --- a/impl/src/main/java/org/jboss/weld/bootstrap/events/ContainerLifecycleEventPreloader.java +++ b/impl/src/main/java/org/jboss/weld/bootstrap/events/ContainerLifecycleEventPreloader.java @@ -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; } diff --git a/impl/src/main/java/org/jboss/weld/executor/AbstractExecutorServices.java b/impl/src/main/java/org/jboss/weld/executor/AbstractExecutorServices.java index 3ba8a31458c..71d8efd3164 100644 --- a/impl/src/main/java/org/jboss/weld/executor/AbstractExecutorServices.java +++ b/impl/src/main/java/org/jboss/weld/executor/AbstractExecutorServices.java @@ -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. diff --git a/impl/src/main/java/org/jboss/weld/executor/DaemonThreadFactory.java b/impl/src/main/java/org/jboss/weld/executor/DaemonThreadFactory.java index 8163c855e06..20a6c539316 100644 --- a/impl/src/main/java/org/jboss/weld/executor/DaemonThreadFactory.java +++ b/impl/src/main/java/org/jboss/weld/executor/DaemonThreadFactory.java @@ -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; } diff --git a/impl/src/main/java/org/jboss/weld/executor/FixedThreadPoolExecutorServices.java b/impl/src/main/java/org/jboss/weld/executor/FixedThreadPoolExecutorServices.java index f6c881fe2ac..f3fc829f87a 100644 --- a/impl/src/main/java/org/jboss/weld/executor/FixedThreadPoolExecutorServices.java +++ b/impl/src/main/java/org/jboss/weld/executor/FixedThreadPoolExecutorServices.java @@ -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); } diff --git a/impl/src/main/java/org/jboss/weld/executor/TimingOutFixedThreadPoolExecutorServices.java b/impl/src/main/java/org/jboss/weld/executor/TimingOutFixedThreadPoolExecutorServices.java index ae1d0d47f3a..0baab0f9844 100644 --- a/impl/src/main/java/org/jboss/weld/executor/TimingOutFixedThreadPoolExecutorServices.java +++ b/impl/src/main/java/org/jboss/weld/executor/TimingOutFixedThreadPoolExecutorServices.java @@ -47,7 +47,7 @@ public TimingOutFixedThreadPoolExecutorServices(int threadPoolSize, long keepAli this.executor = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue(), - 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); diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/event/async/stage/CustomExecutorServices.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/event/async/stage/CustomExecutorServices.java index 0b1f1c30286..feff186b8c7 100644 --- a/tests-arquillian/src/test/java/org/jboss/weld/tests/event/async/stage/CustomExecutorServices.java +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/event/async/stage/CustomExecutorServices.java @@ -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.