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