From 5d7ed98d125a2ac808e0fa4ecd4eaa6bfdbca32d 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 | 3 ++- .../org/jboss/weld/executor/AbstractExecutorServices.java | 4 ++-- .../java/org/jboss/weld/executor/DaemonThreadFactory.java | 8 ++------ .../weld/executor/FixedThreadPoolExecutorServices.java | 3 ++- .../TimingOutFixedThreadPoolExecutorServices.java | 2 +- .../tests/event/async/stage/CustomExecutorServices.java | 2 +- 7 files changed, 11 insertions(+), 13 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 294e868ccda..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 f57fee1216c..6eb515a57d1 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 @@ -55,7 +55,8 @@ public Void call() throws Exception { private final ObserverNotifier notifier; public ContainerLifecycleEventPreloader(int threadPoolSize, ObserverNotifier notifier) { - this.executor = Executors.newFixedThreadPool(threadPoolSize, new DaemonThreadFactory(new ThreadGroup("weld-preloaders"), "weld-preloader-")); + this.executor = Executors.newFixedThreadPool(threadPoolSize, + 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 ec59194fc65..13e02f5616c 100644 --- a/impl/src/main/java/org/jboss/weld/executor/AbstractExecutorServices.java +++ b/impl/src/main/java/org/jboss/weld/executor/AbstractExecutorServices.java @@ -40,8 +40,8 @@ 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-")); + private final ScheduledExecutorService timerExecutor = Executors.newScheduledThreadPool(1, + 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 8a8d4017b4a..7668d081553 100644 --- a/impl/src/main/java/org/jboss/weld/executor/DaemonThreadFactory.java +++ b/impl/src/main/java/org/jboss/weld/executor/DaemonThreadFactory.java @@ -26,20 +26,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 f3802a31e9c..f3fc829f87a 100644 --- a/impl/src/main/java/org/jboss/weld/executor/FixedThreadPoolExecutorServices.java +++ b/impl/src/main/java/org/jboss/weld/executor/FixedThreadPoolExecutorServices.java @@ -36,7 +36,8 @@ 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-")); + this.executor = Executors.newFixedThreadPool(threadPoolSize, + 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 d59f8732c1c..02e07d45bc0 100644 --- a/impl/src/main/java/org/jboss/weld/executor/TimingOutFixedThreadPoolExecutorServices.java +++ b/impl/src/main/java/org/jboss/weld/executor/TimingOutFixedThreadPoolExecutorServices.java @@ -46,7 +46,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.