Java Code Examples for java.lang.management.ThreadMXBean#getThreadCount()
The following examples show how to use
java.lang.management.ThreadMXBean#getThreadCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetStatusServlet.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private static void getSystemInfo( SlaveServerStatus serverStatus ) { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); serverStatus.setCpuCores( cores ); serverStatus.setCpuProcessTime( allThreadsCpuTime ); serverStatus.setUptime( uptime ); serverStatus.setThreadCount( threadCount ); serverStatus.setLoadAvg( loadAvg ); serverStatus.setOsName( osName ); serverStatus.setOsVersion( osVersion ); serverStatus.setOsArchitecture( osArch ); serverStatus.setMemoryFree( freeMemory ); serverStatus.setMemoryTotal( totalMemory ); }
Example 2
Source File: ThreadUtils.java From ats-framework with Apache License 2.0 | 6 votes |
/** * @return a list of all threads started in the JVM. */ public List<Thread> getAllThreads() { final ThreadGroup root = getRootThreadGroup(); final ThreadMXBean thbean = ManagementFactory.getThreadMXBean(); // get the number of all live threads int nAlloc = thbean.getThreadCount(); int n = 0; Thread[] threads; do { nAlloc *= 2; // increase the size since more threads may have been created threads = new Thread[nAlloc]; n = root.enumerate(threads, true); // get all active threads from this thread group } while (n == nAlloc); // stop if all active threads are enumerated List<Thread> res = new ArrayList<Thread>(); for (Thread th : threads) { res.add(th); } return res; }
Example 3
Source File: ThreadsIterator.java From Bats with Apache License 2.0 | 6 votes |
@Override public Object next() { if (!beforeFirst) { throw new IllegalStateException(); } beforeFirst = false; final ThreadsInfo threadsInfo = new ThreadsInfo(); final DrillbitEndpoint endpoint = context.getEndpoint(); threadsInfo.hostname = endpoint.getAddress(); threadsInfo.user_port = endpoint.getUserPort(); final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); threadsInfo.total_threads = threadMXBean.getPeakThreadCount(); threadsInfo.busy_threads = threadMXBean.getThreadCount(); return threadsInfo; }
Example 4
Source File: ThreadSensor.java From swage with Apache License 2.0 | 6 votes |
@Override public void sense(final MetricContext metricContext) { ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); int current = mxBean.getThreadCount(); int peak = mxBean.getPeakThreadCount(); if (peak > historicalPeak) { historicalPeak = peak; } metricContext.record(THREADS, current, Unit.NONE); metricContext.record(PERIODIC_PEAK_THREADS, peak, Unit.NONE); metricContext.record(PEAK_THREADS, historicalPeak, Unit.NONE); mxBean.resetPeakThreadCount(); }
Example 5
Source File: SystemInfo.java From boubei-tss with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/test", method = RequestMethod.GET) @ResponseBody public Object[] getThreadInfos() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true); Long random = null; try { random = SecureRandom.getInstance("SHA1PRNG").nextLong(); } catch (NoSuchAlgorithmException e) { } return new Object[] { threadMXBean.getThreadCount(), threadInfos, random }; }
Example 6
Source File: ThreadLists.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 7
Source File: MonitoredDataImpl.java From visualvm with GNU General Public License v2.0 | 5 votes |
MonitoredDataImpl(JmxSupport jmxSupport,JvmMXBeans jmxModel) { this(jmxSupport); RuntimeMXBean runtimeBean = jmxModel.getRuntimeMXBean(); upTime = runtimeBean.getUptime(); ClassLoadingMXBean classBean = jmxModel.getClassLoadingMXBean(); ThreadMXBean threadBean = jmxModel.getThreadMXBean(); MemoryUsage mem = jmxModel.getMemoryMXBean().getHeapMemoryUsage(); MemoryPoolMXBean permBean = jmxSupport.getPermGenPool(); unloadedClasses = classBean.getUnloadedClassCount(); loadedClasses = classBean.getLoadedClassCount() + unloadedClasses; sharedLoadedClasses = 0; sharedUnloadedClasses = 0; threadsDaemon = threadBean.getDaemonThreadCount(); threadsLive = threadBean.getThreadCount(); threadsLivePeak = threadBean.getPeakThreadCount(); threadsStarted = threadBean.getTotalStartedThreadCount(); applicationTime = 0; genCapacity = new long[2]; genUsed = new long[2]; genMaxCapacity = new long[2]; genCapacity[0] = mem.getCommitted(); genUsed[0] = mem.getUsed(); genMaxCapacity[0] = mem.getMax(); if (permBean != null) { MemoryUsage perm = permBean.getUsage(); genCapacity[1] = perm.getCommitted(); genUsed[1] = perm.getUsed(); genMaxCapacity[1] = perm.getMax(); } }
Example 8
Source File: ThreadLists.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 9
Source File: ThreadLists.java From hottub with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 10
Source File: ThreadUtil.java From cloudhopper-commons with Apache License 2.0 | 5 votes |
/** * Gets all threads in the JVM. This is really a snapshot of all threads * at the time this method is called. * @return An array of all threads currently running in the JVM. */ static public Thread[] getAllThreads() { final ThreadGroup root = getRootThreadGroup(); final ThreadMXBean thbean = ManagementFactory.getThreadMXBean(); int nAlloc = thbean.getThreadCount(); int n = 0; Thread[] threads; do { nAlloc *= 2; threads = new Thread[nAlloc]; n = root.enumerate(threads, true); } while (n == nAlloc); return java.util.Arrays.copyOf(threads, n); }
Example 11
Source File: ThreadLists.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 12
Source File: ThreadLists.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 13
Source File: ThreadLists.java From native-obfuscator with GNU General Public License v3.0 | 5 votes |
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"); } }
Example 14
Source File: ThreadLists.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 15
Source File: ThreadLists.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 16
Source File: ServerStatus.java From hop with Apache License 2.0 | 5 votes |
public ServerStatus() { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); setCpuCores( cores ); setCpuProcessTime( allThreadsCpuTime ); setUptime( uptime ); setThreadCount( threadCount ); setLoadAvg( loadAvg ); setOsName( osName ); setOsVersion( osVersion ); setOsArchitecture( osArch ); setMemoryFree( freeMemory ); setMemoryTotal( totalMemory ); }
Example 17
Source File: ServerStatus.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public ServerStatus() { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[i] ); } long uptime = runtimeMXBean.getUptime(); setCpuCores( cores ); setCpuProcessTime( allThreadsCpuTime ); setUptime( uptime ); setThreadCount( threadCount ); setLoadAvg( loadAvg ); setOsName( osName ); setOsVersion( osVersion ); setOsArchitecture( osArch ); setMemoryFree( freeMemory ); setMemoryTotal( totalMemory ); }
Example 18
Source File: Performance.java From bidder with Apache License 2.0 | 4 votes |
/** * Returns the number of threads. * * @return int. The number of threads in this process */ public static int getThreadCount() { ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); return threadMXBean.getThreadCount(); }
Example 19
Source File: JavaInformations.java From javamelody with Apache License 2.0 | 4 votes |
public JavaInformations(ServletContext servletContext, boolean includeDetails) { // CHECKSTYLE:ON super(); memoryInformations = new MemoryInformations(); tomcatInformationsList = TomcatInformations.buildTomcatInformationsList(); sessionCount = SessionListener.getSessionCount(); sessionAgeSum = SessionListener.getSessionAgeSum(); activeThreadCount = JdbcWrapper.getActiveThreadCount(); usedConnectionCount = JdbcWrapper.getUsedConnectionCount(); activeConnectionCount = JdbcWrapper.getActiveConnectionCount(); maxConnectionCount = JdbcWrapper.getMaxConnectionCount(); transactionCount = JdbcWrapper.getTransactionCount(); systemLoadAverage = buildSystemLoadAverage(); systemCpuLoad = buildSystemCpuLoad(); processCpuTimeMillis = buildProcessCpuTimeMillis(); unixOpenFileDescriptorCount = buildOpenFileDescriptorCount(); unixMaxFileDescriptorCount = buildMaxFileDescriptorCount(); host = Parameters.getHostName() + '@' + Parameters.getHostAddress(); os = buildOS(); availableProcessors = Runtime.getRuntime().availableProcessors(); javaVersion = System.getProperty("java.runtime.name") + ", " + System.getProperty("java.runtime.version"); jvmVersion = System.getProperty("java.vm.name") + ", " + System.getProperty("java.vm.version") + ", " + System.getProperty("java.vm.info"); if (servletContext == null) { serverInfo = null; contextPath = null; contextDisplayName = null; webappVersion = null; } else { serverInfo = servletContext.getServerInfo(); contextPath = Parameters.getContextPath(servletContext); contextDisplayName = servletContext.getServletContextName(); webappVersion = MavenArtifact.getWebappVersion(); } startDate = START_DATE; jvmArguments = buildJvmArguments(); final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); threadCount = threadBean.getThreadCount(); peakThreadCount = threadBean.getPeakThreadCount(); totalStartedThreadCount = threadBean.getTotalStartedThreadCount(); freeDiskSpaceInTemp = Parameters.TEMPORARY_DIRECTORY.getFreeSpace(); usableDiskSpaceInTemp = Parameters.TEMPORARY_DIRECTORY.getUsableSpace(); springBeanExists = SPRING_AVAILABLE && SpringContext.getSingleton() != null; if (includeDetails) { dataBaseVersion = buildDataBaseVersion(); dataSourceDetails = buildDataSourceDetails(); threadInformationsList = buildThreadInformationsList(); cacheInformationsList = CacheInformations.buildCacheInformationsList(); jcacheInformationsList = JCacheInformations.buildJCacheInformationsList(); jobInformationsList = JobInformations.buildJobInformationsList(); hsErrPidList = HsErrPid.buildHsErrPidList(); pid = PID.getPID(); } else { dataBaseVersion = null; dataSourceDetails = null; threadInformationsList = null; cacheInformationsList = null; jcacheInformationsList = null; jobInformationsList = null; hsErrPidList = null; pid = null; } }
Example 20
Source File: JmxInfoProviderSupport.java From ibm-cos-sdk-java with Apache License 2.0 | 4 votes |
@Override public int getThreadCount() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); return threadMXBean.getThreadCount(); }