use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.
the class ThreadLists method main.
public static void main(String[] args) {
// get top-level thread group
ThreadGroup top = Thread.currentThread().getThreadGroup();
ThreadGroup parent;
do {
parent = top.getParent();
if (parent != null)
top = parent;
} while (parent != null);
// get the thread count
int activeCount = top.activeCount();
Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
int threadCount = threadBean.getThreadCount();
long[] threadIds = threadBean.getAllThreadIds();
System.out.println("ThreadGroup: " + activeCount + " active thread(s)");
System.out.println("Thread: " + stackTraces.size() + " stack trace(s) returned");
System.out.println("ThreadMXBean: " + threadCount + " live threads(s)");
System.out.println("ThreadMXBean: " + threadIds.length + " thread Id(s)");
// check results are consistent
boolean failed = false;
if (activeCount != stackTraces.size())
failed = true;
if (activeCount != threadCount)
failed = true;
if (activeCount != threadIds.length)
failed = true;
if (failed) {
throw new RuntimeException("inconsistent results");
}
}
use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.
the class SharedSynchronizer method main.
public static void main(String[] args) throws Exception {
MyThread t = new MyThread();
t.setDaemon(true);
t.start();
ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
if (!tmbean.isSynchronizerUsageSupported()) {
System.out.println("Monitoring of synchronizer usage not supported");
return;
}
long[] result = tmbean.findDeadlockedThreads();
if (result != null) {
throw new RuntimeException("TEST FAILED: result should be null");
}
}
use of java.lang.management.ThreadMXBean in project karaf by apache.
the class ThreadDumpProvider method writeDump.
@Override
protected void writeDump(OutputStreamWriter outputStream) throws Exception {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
outputStream.write("Number of threads: " + threadMXBean.getThreadCount() + "\n");
for (ThreadInfo threadInfo : threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), Integer.MAX_VALUE)) {
outputStream.write(getDumpThreadString(threadInfo) + "\n\n");
}
}
use of java.lang.management.ThreadMXBean in project karaf by apache.
the class EnvironmentDumpProvider method dumpThreadsInformation.
private void dumpThreadsInformation(final PrintWriter outPW) {
final ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
if (null == mxBean) {
return;
}
outPW.println("Threads:");
outPW.printf(INDENT_KEY_VALUE_FORMAT, "live", formatLong(mxBean.getThreadCount())).println();
outPW.printf(INDENT_KEY_VALUE_FORMAT, "daemon", formatLong(mxBean.getDaemonThreadCount())).println();
outPW.printf(INDENT_KEY_VALUE_FORMAT, "peak", formatLong(mxBean.getPeakThreadCount())).println();
outPW.printf(INDENT_KEY_VALUE_FORMAT, "total", formatLong(mxBean.getTotalStartedThreadCount())).println();
}
use of java.lang.management.ThreadMXBean in project asterixdb by apache.
the class GetNodeDetailsJSONWork method getCCDetails.
private ObjectNode getCCDetails() {
ObjectNode o = om.createObjectNode();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
List<GarbageCollectorMXBean> gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
if (includeConfig) {
o.put("os_name", osMXBean.getName());
o.put("arch", osMXBean.getArch());
o.put("os_version", osMXBean.getVersion());
o.put("num_processors", osMXBean.getAvailableProcessors());
o.put("vm_name", runtimeMXBean.getVmName());
o.put("vm_version", runtimeMXBean.getVmVersion());
o.put("vm_vendor", runtimeMXBean.getVmVendor());
o.putPOJO("classpath", runtimeMXBean.getClassPath().split(File.pathSeparator));
o.putPOJO("library_path", runtimeMXBean.getLibraryPath().split(File.pathSeparator));
o.putPOJO("boot_classpath", runtimeMXBean.getBootClassPath().split(File.pathSeparator));
o.putPOJO("input_arguments", runtimeMXBean.getInputArguments());
o.putPOJO("system_properties", runtimeMXBean.getSystemProperties());
o.put("pid", PidHelper.getPid());
}
if (includeStats) {
MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage();
MemoryUsage nonheapUsage = memoryMXBean.getNonHeapMemoryUsage();
List<ObjectNode> gcs = new ArrayList<>();
for (GarbageCollectorMXBean gcMXBean : gcMXBeans) {
ObjectNode gc = om.createObjectNode();
gc.put("name", gcMXBean.getName());
gc.put("collection-time", gcMXBean.getCollectionTime());
gc.put("collection-count", gcMXBean.getCollectionCount());
gcs.add(gc);
}
o.putPOJO("gcs", gcs);
o.put("date", new Date().toString());
o.put("heap_init_size", heapUsage.getInit());
o.put("heap_used_size", heapUsage.getUsed());
o.put("heap_committed_size", heapUsage.getCommitted());
o.put("heap_max_size", heapUsage.getMax());
o.put("nonheap_init_size", nonheapUsage.getInit());
o.put("nonheap_used_size", nonheapUsage.getUsed());
o.put("nonheap_committed_size", nonheapUsage.getCommitted());
o.put("nonheap_max_size", nonheapUsage.getMax());
o.put("thread_count", threadMXBean.getThreadCount());
o.put("peak_thread_count", threadMXBean.getPeakThreadCount());
o.put("started_thread_count", threadMXBean.getTotalStartedThreadCount());
o.put("system_load_average", osMXBean.getSystemLoadAverage());
}
return o;
}
Aggregations