From a9be633816e36823959c988787ac3ab213d6e58d Mon Sep 17 00:00:00 2001 From: John Myers Date: Fri, 13 Mar 2015 13:53:15 -0700 Subject: [PATCH] [Bug 462098] Support setting ThreadGroup in ScheduledExecutorScheduler Signed-off-by: John Gardiner Myers --- .../util/thread/ScheduledExecutorScheduler.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) mode change 100644 => 100755 jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java old mode 100644 new mode 100755 index 55496f4fece..747882b89e7 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java @@ -43,6 +43,7 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch private final String name; private final boolean daemon; private final ClassLoader classloader; + private final ThreadGroup threadGroup; private volatile ScheduledThreadPoolExecutor scheduler; private volatile Thread thread; @@ -57,10 +58,16 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch } public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader threadFactoryClassLoader) + { + this(name, daemon, threadFactoryClassLoader, null); + } + + public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader threadFactoryClassLoader, ThreadGroup threadGroup) { this.name = name == null ? "Scheduler-" + hashCode() : name; this.daemon = daemon; - this.classloader = threadFactoryClassLoader; + this.classloader = threadFactoryClassLoader == null ? Thread.currentThread().getContextClassLoader() : threadFactoryClassLoader; + this.threadGroup = threadGroup; } @Override @@ -71,7 +78,7 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch @Override public Thread newThread(Runnable r) { - Thread thread = ScheduledExecutorScheduler.this.thread = new Thread(r, name); + Thread thread = ScheduledExecutorScheduler.this.thread = new Thread(threadGroup, r, name); thread.setDaemon(daemon); thread.setContextClassLoader(classloader); return thread; @@ -123,11 +130,11 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch } } - private class ScheduledFutureTask implements Task + private static class ScheduledFutureTask implements Task { private final ScheduledFuture scheduledFuture; - public ScheduledFutureTask(ScheduledFuture scheduledFuture) + ScheduledFutureTask(ScheduledFuture scheduledFuture) { this.scheduledFuture = scheduledFuture; }