Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WELD-2755 Remove usage of ThreadGroup from Weld executors #2884

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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
Loading