From 30fd8323f4f824ecd405333cb0770c628767759d Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 9 May 2016 15:52:16 +0200 Subject: [PATCH] Added jobs to detailed dump. --- .../jetty/util/thread/QueuedThreadPool.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index b52daa037f0..ba3d4060778 100755 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -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 _threads=new ConcurrentHashSet(); + private final ConcurrentHashSet _threads=new ConcurrentHashSet<>(); private final Object _joinLock = new Object(); private final BlockingQueue _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 dump = new ArrayList<>(getMaxThreads()); + List 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 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 queue) { throw new UnsupportedOperationException("Use constructor injection");