[Bug 462098] Support setting ThreadGroup in ScheduledExecutorScheduler

Signed-off-by: John Gardiner Myers <jgmyers@proofpoint.com>
This commit is contained in:
John Myers 2015-03-13 13:53:15 -07:00 committed by Greg Wilkins
parent c8b84e0291
commit a9be633816
1 changed files with 11 additions and 4 deletions

View File

@ -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;
}