Issue #5201 - simplify the QueuedThreadPool detailed dump

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-09-03 06:57:18 +10:00
parent 001def4905
commit 0a59a2b090
1 changed files with 25 additions and 60 deletions

View File

@ -701,74 +701,39 @@ public class QueuedThreadPool extends ContainerLifeCycle implements ThreadFactor
public void dump(Appendable out, String indent) throws IOException
{
List<Object> threads = new ArrayList<>(getMaxThreads());
for (final Thread thread : _threads)
for (Thread thread : _threads)
{
final StackTraceElement[] trace = thread.getStackTrace();
String knownMethod = "";
for (StackTraceElement t : trace)
{
if ("idleJobPoll".equals(t.getMethodName()) && t.getClassName().equals(Runner.class.getName()))
{
knownMethod = "IDLE ";
break;
}
StackTraceElement[] trace = thread.getStackTrace();
String known = getKnownMethod(trace);
String baseThreadInfo = String.format("%s %s %s %d", thread.getId(), thread.getName(), thread.getState(), thread.getPriority());
if ("reservedWait".equals(t.getMethodName()) && t.getClassName().endsWith("ReservedThread"))
{
knownMethod = "RESERVED ";
break;
}
if ("select".equals(t.getMethodName()) && t.getClassName().endsWith("SelectorProducer"))
{
knownMethod = "SELECTING ";
break;
}
if ("accept".equals(t.getMethodName()) && t.getClassName().contains("ServerConnector"))
{
knownMethod = "ACCEPTING ";
break;
}
}
final String known = knownMethod;
if (isDetailedDump())
{
threads.add(new Dumpable()
{
@Override
public void dump(Appendable out, String indent) throws IOException
{
if (StringUtil.isBlank(known))
Dumpable.dumpObjects(out, indent, String.format("%s %s %s %d", thread.getId(), thread.getName(), thread.getState(), thread.getPriority()), (Object[])trace);
else
Dumpable.dumpObjects(out, indent, String.format("%s %s %s %s %d", thread.getId(), thread.getName(), known, thread.getState(), thread.getPriority()));
}
@Override
public String dump()
{
return null;
}
});
}
if (!StringUtil.isBlank(known))
threads.add(baseThreadInfo + " " + known);
else if (isDetailedDump())
threads.add((Dumpable)(o, i) -> Dumpable.dumpObjects(o, i, baseThreadInfo, (Object[])trace));
else
{
int p = thread.getPriority();
threads.add(thread.getId() + " " + thread.getName() + " " + known + thread.getState() + " @ " + (trace.length > 0 ? trace[0] : "???") + (p == Thread.NORM_PRIORITY ? "" : (" prio=" + p)));
}
threads.add(baseThreadInfo + " @ " + (trace.length > 0 ? trace[0].toString() : "???"));
}
dumpObjects(out, indent, new DumpableCollection("threads", threads));
if (isDetailedDump())
dumpObjects(out, indent, new DumpableCollection("jobs", new ArrayList<>(getQueue())));
}
private String getKnownMethod(StackTraceElement[] trace)
{
for (StackTraceElement t : trace)
{
List<Runnable> jobs = new ArrayList<>(getQueue());
dumpObjects(out, indent, new DumpableCollection("threads", threads), new DumpableCollection("jobs", jobs));
}
else
{
dumpObjects(out, indent, new DumpableCollection("threads", threads));
if ("idleJobPoll".equals(t.getMethodName()) && t.getClassName().equals(Runner.class.getName()))
return "IDLE";
if ("reservedWait".equals(t.getMethodName()) && t.getClassName().endsWith("ReservedThread"))
return "RESERVED";
if ("select".equals(t.getMethodName()) && t.getClassName().endsWith("SelectorProducer"))
return "SELECTING";
if ("accept".equals(t.getMethodName()) && t.getClassName().contains("ServerConnector"))
return "ACCEPTING";
}
return "";
}
@Override