Skip to content

Commit

Permalink
Issue #5201 - simplify the QueuedThreadPool detailed dump
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Sep 2, 2020
1 parent 001def4 commit 0a59a2b
Showing 1 changed file with 26 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -701,74 +701,39 @@ protected void removeThread(Thread thread)
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;
}

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;
}
});
}
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 (!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
Expand Down

0 comments on commit 0a59a2b

Please sign in to comment.