use of java.lang.management.ThreadInfo in project druid by alibaba.
the class Case4 method p0.
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(threadCount);
final CountDownLatch dumpLatch = new CountDownLatch(1);
Thread[] threads = new Thread[threadCount];
final TableOperator operator = new TableOperator();
operator.setDataSource(dataSource);
operator.createTable();
for (int i = 0; i < threadCount; ++i) {
Thread thread = new Thread() {
public void run() {
try {
startLatch.await();
for (int i = 0; i < LOOP_COUNT; ++i) {
operator.insert();
}
} catch (Exception ex) {
ex.printStackTrace();
}
endLatch.countDown();
try {
dumpLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
threads[i] = thread;
thread.start();
}
long startMillis = System.currentTimeMillis();
long startYGC = TestUtil.getYoungGC();
long startFullGC = TestUtil.getFullGC();
startLatch.countDown();
endLatch.await();
long[] threadIdArray = new long[threads.length];
for (int i = 0; i < threads.length; ++i) {
threadIdArray[i] = threads[i].getId();
}
ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray);
dumpLatch.countDown();
operator.dropTable();
long blockedCount = 0;
long waitedCount = 0;
for (int i = 0; i < threadInfoArray.length; ++i) {
ThreadInfo threadInfo = threadInfoArray[i];
blockedCount += threadInfo.getBlockedCount();
waitedCount += threadInfo.getWaitedCount();
}
long millis = System.currentTimeMillis() - startMillis;
long ygc = TestUtil.getYoungGC() - startYGC;
long fullGC = TestUtil.getFullGC() - startFullGC;
System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC + " blocked " + //
NumberFormat.getInstance().format(blockedCount) + " waited " + NumberFormat.getInstance().format(waitedCount));
}
use of java.lang.management.ThreadInfo in project intellij-plugins by JetBrains.
the class HealthUtils method logThreads.
/**
* Log data about threads to the provided instrumentation builder
*
* @param instrumentation builder to log data to
*/
public static void logThreads(InstrumentationBuilder instrumentation) {
java.lang.management.ThreadMXBean th = ManagementFactory.getThreadMXBean();
ThreadInfo[] thInfos = th.getThreadInfo(th.getAllThreadIds(), Integer.MAX_VALUE);
instrumentation.metric("threads-count", thInfos.length);
for (ThreadInfo thInfo : thInfos) {
if (thInfo == null) {
instrumentation.metric("Thread-Name", "<unknown>");
continue;
}
instrumentation.metric("Thread-Name", thInfo.getThreadName());
instrumentation.metric("Thread-ID", thInfo.getThreadId());
instrumentation.metric("Thread-State", thInfo.getThreadState().toString());
instrumentation.metric("Blocked-Count", thInfo.getBlockedCount());
instrumentation.metric("Blocked-Time", thInfo.getBlockedTime());
instrumentation.metric("Waited-Count", thInfo.getWaitedCount());
instrumentation.metric("Waited-Time", thInfo.getWaitedTime());
instrumentation.data("Thread-ST", Base64.encodeBytes(stackTraceToString(thInfo.getStackTrace()).getBytes()));
}
}
use of java.lang.management.ThreadInfo in project OpenAM by OpenRock.
the class RecordReport method getThreadDump.
public String getThreadDump() {
StringBuilder report = new StringBuilder();
report.append("DATE : ").append(dateFormat.format(new Date())).append("\n");
final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
for (ThreadInfo threadInfo : threadInfos) {
report.append(threadInfo);
}
return report.toString();
}
use of java.lang.management.ThreadInfo in project opennms by OpenNMS.
the class ThreadReportPlugin method getEntries.
@Override
public Map<String, Resource> getEntries() {
final Map<String, Resource> map = new TreeMap<String, Resource>();
final StringBuilder sb = new StringBuilder();
try {
final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
for (final ThreadInfo info : threads) {
sb.append(info.toString());
}
map.put("ThreadDump.txt", getResource(sb.toString()));
} catch (final Exception e) {
LOG.debug("Unable to get thread dump.", e);
}
return map;
}
use of java.lang.management.ThreadInfo in project geode by apache.
the class DeadlockDetector method getThreadReference.
/**
* Get an object suitable for querying the findDependencies method for a given thread.
*/
public static ThreadReference getThreadReference(String locality, Thread thread) {
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo info = bean.getThreadInfo(thread.getId(), Integer.MAX_VALUE);
return new LocalThread(locality, info);
}
Aggregations