List of usage examples for java.lang.management ThreadMXBean getDaemonThreadCount
public int getDaemonThreadCount();
From source file:com.amazonaws.client.metrics.support.JmxInfoProviderSupport.java
@Override public int getDaemonThreadCount() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); return threadMXBean.getDaemonThreadCount(); }
From source file:com.snowstore.mercury.core.metric.SystemPublicMetrics.java
/** * Add thread metrics.// ww w. j av a 2 s . c om * * @param result * the result */ protected void addThreadMetrics(Collection<Metric<?>> result) { ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean(); result.add(new Metric<Long>("threads.peak", (long) threadMxBean.getPeakThreadCount())); result.add(new Metric<Long>("threads.daemon", (long) threadMxBean.getDaemonThreadCount())); result.add(new Metric<Long>("threads", (long) threadMxBean.getThreadCount())); }
From source file:com.thoughtworks.go.server.service.support.ThreadInformationProvider.java
private Map<String, Object> getThreadCount(ThreadMXBean threadMXBean) { LinkedHashMap<String, Object> count = new LinkedHashMap<>(); count.put("Current", threadMXBean.getThreadCount()); count.put("Total", threadMXBean.getTotalStartedThreadCount()); count.put("Daemon", threadMXBean.getDaemonThreadCount()); count.put("Peak", threadMXBean.getPeakThreadCount()); return count; }
From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java
private void threadInfo(ThreadMXBean threadMXBean, InformationStringBuilder builder) { builder.addSection("Thread information"); builder.append(String.format("Current: %s, Total: %s, Daemon: %s, Peak: %s\n", threadMXBean.getThreadCount(), threadMXBean.getTotalStartedThreadCount(), threadMXBean.getDaemonThreadCount(), threadMXBean.getPeakThreadCount())); long[] deadlockedThreads = threadMXBean.findDeadlockedThreads(); if (deadlockedThreads != null && deadlockedThreads.length > 0) { builder.append(String.format("Found %s dead locked threads. Here is there information.\n", deadlockedThreads.length)); for (long deadlockedThread : deadlockedThreads) { ThreadInfo threadInfo = threadMXBean.getThreadInfo(deadlockedThread); LockInfo lockInfo = threadInfo.getLockInfo(); if (lockInfo != null) { builder.append(String.format("LockInfo: %s", lockInfo)); } else { builder.append("This thread is not waiting for any locks\n"); }/* w ww.j a v a2 s. c om*/ builder.append(String.format("Monitor Info - Stack Frame where locks were taken.\n")); MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors(); for (MonitorInfo lockedMonitor : lockedMonitors) { builder.append(String.format("Monitor for class '%s' taken at stack frame '%s'.", lockedMonitor.getClassName(), lockedMonitor.getLockedStackFrame())); } builder.append("The stack trace of the deadlocked thread\n"); builder.append(Arrays.toString(threadInfo.getStackTrace())); } } builder.addSubSection("All thread stacktraces"); ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo threadInfo : threadInfos) { builder.append(String.format("%s, %s, %s\n", threadInfo.getThreadId(), threadInfo.getThreadName(), threadInfo.getThreadState())); MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors(); builder.append("Locked Monitors:\n"); for (MonitorInfo lockedMonitor : lockedMonitors) { builder.append(String.format("%s at %s", lockedMonitor, lockedMonitor.getLockedStackFrame())); } LockInfo[] lockedSynchronizers = threadInfo.getLockedSynchronizers(); builder.append("Locked Synchronizers:\n"); for (LockInfo lockedSynchronizer : lockedSynchronizers) { builder.append(lockedSynchronizer); } builder.append("Stacktrace:\n "); builder.append(StringUtils.join(threadInfo.getStackTrace(), "\n ")); builder.append("\n\n"); } }
From source file:com.thoughtworks.go.server.service.support.ThreadInformationProvider.java
@Override public void appendInformation(InformationStringBuilder builder) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); builder.addSection("Thread information"); builder.append(String.format("Current: %s, Total: %s, Daemon: %s, Peak: %s\n", threadMXBean.getThreadCount(), threadMXBean.getTotalStartedThreadCount(), threadMXBean.getDaemonThreadCount(), threadMXBean.getPeakThreadCount())); long[] deadlockedThreads = threadMXBean.findDeadlockedThreads(); if (deadlockedThreads != null && deadlockedThreads.length > 0) { builder.append(String.format("Found %s dead locked threads. Here is there information.\n", deadlockedThreads.length)); for (long deadlockedThread : deadlockedThreads) { ThreadInfo threadInfo = threadMXBean.getThreadInfo(deadlockedThread); LockInfo lockInfo = threadInfo.getLockInfo(); if (lockInfo != null) { builder.append(String.format("LockInfo: %s", lockInfo)); } else { builder.append("This thread is not waiting for any locks\n"); }// w w w . ja va 2 s . c o m builder.append(String.format("Monitor Info - Stack Frame where locks were taken.\n")); MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors(); for (MonitorInfo lockedMonitor : lockedMonitors) { builder.append(String.format("Monitor for class '%s' taken at stack frame '%s'.", lockedMonitor.getClassName(), lockedMonitor.getLockedStackFrame())); } builder.append("The stack trace of the deadlocked thread\n"); builder.append(Arrays.toString(threadInfo.getStackTrace())); } } builder.addSubSection("All thread stacktraces"); ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo threadInfo : threadInfos) { builder.append(String.format("%s, %s, %s\n", threadInfo.getThreadId(), threadInfo.getThreadName(), threadInfo.getThreadState())); MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors(); builder.append("Locked Monitors:\n"); for (MonitorInfo lockedMonitor : lockedMonitors) { builder.append(String.format("%s at %s", lockedMonitor, lockedMonitor.getLockedStackFrame())); } LockInfo[] lockedSynchronizers = threadInfo.getLockedSynchronizers(); builder.append("Locked Synchronizers:\n"); for (LockInfo lockedSynchronizer : lockedSynchronizers) { builder.append(lockedSynchronizer); } builder.append("Stacktrace:\n "); builder.append(StringUtils.join(threadInfo.getStackTrace(), "\n ")); builder.append("\n\n"); } }
From source file:com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog.java
/** * Initializes the infos object.<p> *//*from w w w. j ava 2s . c o m*/ protected void initInfosObject() { com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean(); setCpuCount("" + osBean.getAvailableProcessors()); double usage = com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog .getCPUUsage(getSession()); usage = Math.round(usage * 100) / 100; setCpuUsage("" + 100 * usage + "%"); setLoadedClassesCount("" + classesBean.getLoadedClassCount()); setUnloadedClassesCount("" + classesBean.getUnloadedClassCount()); setTotalLoadedClassesCount("" + classesBean.getTotalLoadedClassCount()); setThreadsCount("" + threadBean.getThreadCount()); setThreadsStartedCount("" + threadBean.getTotalStartedThreadCount()); setThreadsPeakCount("" + threadBean.getPeakThreadCount()); setThreadsDaemonCount("" + threadBean.getDaemonThreadCount()); Object o; if (CmsStringUtil.isEmpty(getParamAction())) { o = new CmsAdminSettings(getSession()); } else { // this is not the initial call, get the job object from session o = getDialogObject(); } if (!(o instanceof CmsAdminSettings)) { // create a new history settings handler object m_adminSettings = new CmsAdminSettings(getSession()); } else { // reuse html import handler object stored in session m_adminSettings = (CmsAdminSettings) o; } setParamCloseLink(getJsp().link( "/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/cpu_and_threads.jsp")); }
From source file:org.fluentd.jvmwatcher.data.JvmStateLog.java
/** * @param clientPrixy/* w ww. j ava 2 s. com*/ * @return */ public static JvmStateLog makeJvmStateLog(JvmClientProxy clientProxy) { JvmStateLog ret = new JvmStateLog(); try { // set log time ret.logDateTime_ = System.currentTimeMillis(); // ClassLoadingMXBean ClassLoadingMXBean classLoadingBean = clientProxy.getClassLoadingMXBean(); if (null != classLoadingBean) { ret.classLoadedCount_ = classLoadingBean.getLoadedClassCount(); ret.classUnloadedCount_ = classLoadingBean.getUnloadedClassCount(); ret.classTotalLoadedCount_ = classLoadingBean.getTotalLoadedClassCount(); } // CompilationMXBean CompilationMXBean compilationBean = clientProxy.getCompilationMXBean(); if (null != compilationBean) { ret.compileTime_ = compilationBean.getTotalCompilationTime(); } // MemoryMXBean MemoryMXBean memoryBean = clientProxy.getMemoryMXBean(); if (null != memoryBean) { ret.heapSize_ = memoryBean.getHeapMemoryUsage(); ret.notheapSize_ = memoryBean.getNonHeapMemoryUsage(); ret.pendingFinalizationCount_ = memoryBean.getObjectPendingFinalizationCount(); } // ThreadMXBean ThreadMXBean threadBean = clientProxy.getThreadMXBean(); if (null != threadBean) { ret.threadCount_ = threadBean.getThreadCount(); ret.daemonThreadCount_ = threadBean.getDaemonThreadCount(); ret.peakThreadCount_ = threadBean.getPeakThreadCount(); } // OperatingSystemMXBean OperatingSystemMXBean OpeSysBean = clientProxy.getOperatingSystemMXBean(); if (null != OpeSysBean) { ret.osAvailableProcessors_ = OpeSysBean.getAvailableProcessors(); ret.osSystemLoadAverage_ = OpeSysBean.getSystemLoadAverage(); } // com.sun.management.OperatingSystemMXBean com.sun.management.OperatingSystemMXBean sunOpeSysBean = clientProxy.getSunOperatingSystemMXBean(); if (null != sunOpeSysBean) { ret.committedVirtualMemorySize_ = sunOpeSysBean.getCommittedVirtualMemorySize(); ret.freePhysicalMemorySize_ = sunOpeSysBean.getFreePhysicalMemorySize(); ret.freeSwapSpaceSize_ = sunOpeSysBean.getFreeSwapSpaceSize(); ret.processCpuTime_ = sunOpeSysBean.getProcessCpuTime(); ret.totalPhysicalMemorySize_ = sunOpeSysBean.getTotalPhysicalMemorySize(); ret.totalSwapSpaceSize_ = sunOpeSysBean.getTotalSwapSpaceSize(); } // RuntimeMXBean RuntimeMXBean runtimeBean = clientProxy.getRuntimeMXBean(); if (null != runtimeBean) { ret.jvmUpTime_ = runtimeBean.getUptime(); } // MemoryPoolMXBean Collection<MemoryPoolClientProxy> memoryPoolBeansColl = clientProxy.getMemoryPoolClientProxies(); if (null != memoryPoolBeansColl) { ret.memoryPoolStateColl_ = new ArrayList<MemoryPoolState>(); for (MemoryPoolClientProxy elem : memoryPoolBeansColl) { if (null != elem) { MemoryPoolState state = elem.getStat(); if (null != state) { // add MemoryPoolState ret.memoryPoolStateColl_.add(state); } } } } // GarbageCollectorMXBean Collection<GarbageCollectorMXBean> garbageCollBeansColl = clientProxy.getGarbageCollectorMXBeans(); if (null != garbageCollBeansColl) { ret.gcCollectorState_ = new ArrayList<GarbageCollectorState>(); for (GarbageCollectorMXBean elem : garbageCollBeansColl) { if (null != elem) { long collectionCount = elem.getCollectionCount(); long collectionTime = elem.getCollectionTime(); String memoryManagerName = elem.getName(); GarbageCollectorState state = new GarbageCollectorState(memoryManagerName, collectionCount, collectionTime); // add GarbageCollectorState ret.gcCollectorState_.add(state); } } } } catch (IOException ex) { log.error(ex); // close JvmClientProxy clientProxy.disconnect(); } catch (Exception ex) { log.error(ex); // close JvmClientProxy clientProxy.disconnect(); } return ret; }