use of org.eclipse.jetty.util.component.Dumpable in project jetty.project by eclipse.
the class QueuedThreadPool method dump.
@Override
public void dump(Appendable out, String indent) throws IOException {
List<Object> threads = new ArrayList<>(getMaxThreads());
for (final Thread thread : _threads) {
final StackTraceElement[] trace = thread.getStackTrace();
boolean inIdleJobPoll = false;
for (StackTraceElement t : trace) {
if ("idleJobPoll".equals(t.getMethodName())) {
inIdleJobPoll = true;
break;
}
}
final boolean idle = inIdleJobPoll;
if (isDetailedDump()) {
threads.add(new Dumpable() {
@Override
public void dump(Appendable out, String indent) throws IOException {
out.append(String.valueOf(thread.getId())).append(' ').append(thread.getName()).append(' ').append(thread.getState().toString()).append(idle ? " IDLE" : "");
if (thread.getPriority() != Thread.NORM_PRIORITY)
out.append(" prio=").append(String.valueOf(thread.getPriority()));
out.append(System.lineSeparator());
if (!idle)
ContainerLifeCycle.dump(out, indent, Arrays.asList(trace));
}
@Override
public String dump() {
return null;
}
});
} else {
int p = thread.getPriority();
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, threads, Collections.singletonList(new DumpableCollection("jobs", jobs)));
}
use of org.eclipse.jetty.util.component.Dumpable in project jetty.project by eclipse.
the class ThreadMonitorTest method monitorTest.
@Ignore
@Test
public void monitorTest() throws Exception {
try (StacklessLogging stackless = new StacklessLogging(ThreadMonitor.class)) {
final AtomicInteger countLogs = new AtomicInteger(0);
final AtomicInteger countSpin = new AtomicInteger(0);
ThreadMonitor monitor = new ThreadMonitor(1000, 50, 1, 1) {
@Override
protected void logThreadInfo(boolean logAll) {
if (logAll)
countLogs.incrementAndGet();
else
countSpin.incrementAndGet();
super.logThreadInfo(logAll);
}
};
monitor.setDumpable(new Dumpable() {
public void dump(Appendable out, String indent) throws IOException {
out.append(dump());
}
public String dump() {
return "Dump Spinning";
}
});
monitor.logCpuUsage(2000, 0);
monitor.start();
Random rnd = new Random();
for (long cnt = 0; cnt < 100; cnt++) {
long value = rnd.nextLong() % 50 + 50;
Sleeper sleeper = new Sleeper(value);
Thread runner = new Thread(sleeper);
runner.setDaemon(true);
runner.start();
}
Spinner spinner = new Spinner();
Thread runner = new Thread(spinner);
runner.start();
Thread.sleep(DURATION);
spinner.setDone();
monitor.stop();
assertTrue(countLogs.get() >= 1);
assertTrue(countSpin.get() >= 2);
}
}
use of org.eclipse.jetty.util.component.Dumpable in project jetty.project by eclipse.
the class NamingContext method dump.
/* ------------------------------------------------------------ */
public void dump(Appendable out, String indent) throws IOException {
out.append(this.getClass().getSimpleName()).append("@").append(Long.toHexString(this.hashCode())).append("\n");
int size = _bindings.size();
int i = 0;
for (Map.Entry<String, Binding> entry : ((Map<String, Binding>) _bindings).entrySet()) {
boolean last = ++i == size;
out.append(indent).append(" +- ").append(entry.getKey()).append(": ");
Binding binding = entry.getValue();
Object value = binding.getObject();
if ("comp".equals(entry.getKey()) && value instanceof Reference && "org.eclipse.jetty.jndi.ContextFactory".equals(((Reference) value).getFactoryClassName())) {
ContextFactory.dump(out, indent + (last ? " " : " | "));
} else if (value instanceof Dumpable) {
((Dumpable) value).dump(out, indent + (last ? " " : " | "));
} else {
out.append(value.getClass().getSimpleName()).append("=");
out.append(String.valueOf(value).replace('\n', '|').replace('\r', '|'));
out.append("\n");
}
}
}
Aggregations