Implemented dump() to print out the scheduler thread stack trace.
This commit is contained in:
parent
e3ae501db8
commit
1274bb9e43
|
@ -18,13 +18,17 @@
|
|||
|
||||
package org.eclipse.jetty.util.thread;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
|
||||
/**
|
||||
* Implementation of {@link Scheduler} based on JDK's {@link ScheduledThreadPoolExecutor}.
|
||||
|
@ -34,12 +38,13 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|||
* queue even if the task did not fire, which provides a huge benefit in the performance
|
||||
* of garbage collection in young generation.
|
||||
*/
|
||||
public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Scheduler
|
||||
public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Scheduler, Dumpable
|
||||
{
|
||||
private final String name;
|
||||
private final boolean daemon;
|
||||
private final ClassLoader classloader;
|
||||
private volatile ScheduledThreadPoolExecutor scheduler;
|
||||
private ClassLoader classloader;
|
||||
private volatile Thread thread;
|
||||
|
||||
public ScheduledExecutorScheduler()
|
||||
{
|
||||
|
@ -66,7 +71,7 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch
|
|||
@Override
|
||||
public Thread newThread(Runnable r)
|
||||
{
|
||||
Thread thread = new Thread(r, name);
|
||||
Thread thread = ScheduledExecutorScheduler.this.thread = new Thread(r, name);
|
||||
thread.setDaemon(daemon);
|
||||
thread.setContextClassLoader(classloader);
|
||||
return thread;
|
||||
|
@ -76,8 +81,6 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch
|
|||
super.doStart();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
|
@ -92,7 +95,24 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch
|
|||
ScheduledFuture<?> result = scheduler.schedule(task, delay, unit);
|
||||
return new ScheduledFutureTask(result);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String dump()
|
||||
{
|
||||
return ContainerLifeCycle.dump(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
ContainerLifeCycle.dumpObject(out, this);
|
||||
Thread thread = this.thread;
|
||||
if (thread != null)
|
||||
{
|
||||
List<StackTraceElement> frames = Arrays.asList(thread.getStackTrace());
|
||||
ContainerLifeCycle.dump(out, indent, frames);
|
||||
}
|
||||
}
|
||||
|
||||
private class ScheduledFutureTask implements Task
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue