Skip to content

Commit

Permalink
Added jobs to detailed dump.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbordet committed May 11, 2016
1 parent bdafea3 commit 30fd832
Showing 1 changed file with 20 additions and 19 deletions.
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -126,13 +127,7 @@ protected void doStop() throws Exception
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);

Expand Down Expand Up @@ -166,7 +161,7 @@ public void run()
if (size > 0)
{
Thread.yield();

if (LOG.isDebugEnabled())
{
for (Thread unstopped : _threads)
Expand All @@ -193,7 +188,7 @@ public void run()
}

/**
* Thread Pool should use Daemon Threading.
* Thread Pool should use Daemon Threading.
*
* @param daemon true to enable delegation
* @see Thread#setDaemon(boolean)
Expand Down Expand Up @@ -332,10 +327,10 @@ public int getThreadsPriority()
{
return _priority;
}

/**
* Get the size of the job queue.
*
*
* @return Number of jobs queued waiting for a thread
*/
@ManagedAttribute("Size of the job queue")
Expand All @@ -346,7 +341,7 @@ public int getQueueSize()

/**
* Is thread pool using daemon threading
*
*
* @return true if delegating to named or anonymous pool
* @see Thread#setDaemon(boolean)
*/
Expand All @@ -365,7 +360,7 @@ public void setDetailedDump(boolean detailedDump)
{
_detailedDump = detailedDump;
}

@Override
public void execute(Runnable job)
{
Expand Down Expand Up @@ -428,7 +423,7 @@ public int getBusyThreads()
{
return getThreads() - getIdleThreads();
}

/**
* @return True if the pool is at maxThreads and there are not more idle threads than queued jobs
*/
Expand Down Expand Up @@ -487,7 +482,7 @@ public String dump()
@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();
Expand All @@ -504,7 +499,7 @@ public void dump(Appendable out, String indent) throws IOException

if (isDetailedDump())
{
dump.add(new Dumpable()
threads.add(new Dumpable()
{
@Override
public void dump(Appendable out, String indent) throws IOException
Expand All @@ -527,12 +522,16 @@ public String dump()
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
Expand Down Expand Up @@ -664,7 +663,9 @@ protected BlockingQueue<Runnable> getQueue()

/**
* @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");
Expand Down

0 comments on commit 30fd832

Please sign in to comment.