Added jobs to detailed dump.

This commit is contained in:
Simone Bordet 2016-05-09 15:52:16 +02:00
parent bdafea3e96
commit 30fd8323f4
1 changed files with 20 additions and 19 deletions

View File

@ -22,6 +22,7 @@ package org.eclipse.jetty.util.thread;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionException;
@ -51,7 +52,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
private final AtomicInteger _threadsStarted = new AtomicInteger();
private final AtomicInteger _threadsIdle = new AtomicInteger();
private final AtomicLong _lastShrink = new AtomicLong();
private final ConcurrentHashSet<Thread> _threads=new ConcurrentHashSet<Thread>();
private final ConcurrentHashSet<Thread> _threads=new ConcurrentHashSet<>();
private final Object _joinLock = new Object();
private final BlockingQueue<Runnable> _jobs;
private final ThreadGroup _threadGroup;
@ -126,13 +127,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
jobs.clear();
// Fill job Q with noop jobs to wakeup idle
Runnable noop = new Runnable()
{
@Override
public void run()
{
}
};
Runnable noop = () -> {};
for (int i = _threadsStarted.get(); i-- > 0; )
jobs.offer(noop);
@ -166,7 +161,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
if (size > 0)
{
Thread.yield();
if (LOG.isDebugEnabled())
{
for (Thread unstopped : _threads)
@ -193,7 +188,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
}
/**
* Thread Pool should use Daemon Threading.
* Thread Pool should use Daemon Threading.
*
* @param daemon true to enable delegation
* @see Thread#setDaemon(boolean)
@ -332,10 +327,10 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
{
return _priority;
}
/**
* Get the size of the job queue.
*
*
* @return Number of jobs queued waiting for a thread
*/
@ManagedAttribute("Size of the job queue")
@ -346,7 +341,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
/**
* Is thread pool using daemon threading
*
*
* @return true if delegating to named or anonymous pool
* @see Thread#setDaemon(boolean)
*/
@ -365,7 +360,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
{
_detailedDump = detailedDump;
}
@Override
public void execute(Runnable job)
{
@ -428,7 +423,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
{
return getThreads() - getIdleThreads();
}
/**
* @return True if the pool is at maxThreads and there are not more idle threads than queued jobs
*/
@ -487,7 +482,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
@Override
public void dump(Appendable out, String indent) throws IOException
{
List<Object> dump = new ArrayList<>(getMaxThreads());
List<Object> threads = new ArrayList<>(getMaxThreads());
for (final Thread thread : _threads)
{
final StackTraceElement[] trace = thread.getStackTrace();
@ -504,7 +499,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
if (isDetailedDump())
{
dump.add(new Dumpable()
threads.add(new Dumpable()
{
@Override
public void dump(Appendable out, String indent) throws IOException
@ -527,12 +522,16 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
else
{
int p=thread.getPriority();
dump.add(thread.getId() + " " + thread.getName() + " " + thread.getState() + " @ " + (trace.length > 0 ? trace[0] : "???") + (idle ? " IDLE" : "")+ (p==Thread.NORM_PRIORITY?"":(" prio="+p)));
threads.add(thread.getId() + " " + thread.getName() + " " + thread.getState() + " @ " + (trace.length > 0 ? trace[0] : "???") + (idle ? " IDLE" : "")+ (p==Thread.NORM_PRIORITY?"":(" prio="+p)));
}
}
List<Runnable> jobs = Collections.emptyList();
if (isDetailedDump())
jobs = new ArrayList<>(getQueue());
ContainerLifeCycle.dumpObject(out, this);
ContainerLifeCycle.dump(out, indent, dump);
ContainerLifeCycle.dump(out, indent, threads, jobs);
}
@Override
@ -664,7 +663,9 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
/**
* @param queue the job queue
* @deprecated pass the queue to the constructor instead
*/
@Deprecated
public void setQueue(BlockingQueue<Runnable> queue)
{
throw new UnsupportedOperationException("Use constructor injection");