List of usage examples for java.lang.management ThreadMXBean getThreadCount
public int getThreadCount();
From source file:net.bull.javamelody.internal.model.JavaInformations.java
public JavaInformations(ServletContext servletContext, boolean includeDetails) { // CHECKSTYLE:ON super();//w w w . ja v a 2s .c om 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(); springBeanExists = SPRING_AVAILABLE && SpringContext.getSingleton() != null; if (includeDetails) { dataBaseVersion = buildDataBaseVersion(); dataSourceDetails = buildDataSourceDetails(); threadInformationsList = buildThreadInformationsList(); cacheInformationsList = CacheInformations.buildCacheInformationsList(); jobInformationsList = JobInformations.buildJobInformationsList(); pid = PID.getPID(); } else { dataBaseVersion = null; dataSourceDetails = null; threadInformationsList = null; cacheInformationsList = null; jobInformationsList = null; pid = null; } }
From source file:com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog.java
/** * Initializes the infos object.<p> *//*from w w w.ja va 2 s. 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:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@GET @RequireAdmin/*from www. j a v a2s . c o m*/ @APIDescription("Gets the application system status") @Produces({ MediaType.APPLICATION_JSON }) @DataType(ApplicationStatus.class) @Path("/status") public Response getApplicationStatus() { OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ApplicationStatus applicationStatus = new ApplicationStatus(); applicationStatus.setApplicationVersion(PropertiesManager.getApplicationVersion()); applicationStatus.setProcessorCount(operatingSystemMXBean.getAvailableProcessors()); applicationStatus.setSystemLoad(operatingSystemMXBean.getSystemLoadAverage()); applicationStatus.setSystemProperties(runtimeMXBean.getSystemProperties()); applicationStatus.getHeapMemoryStatus().setName("Heap"); applicationStatus.getHeapMemoryStatus().setDetails(memoryMXBean.getHeapMemoryUsage().toString()); applicationStatus.getHeapMemoryStatus() .setInitKb(memoryMXBean.getHeapMemoryUsage().getInit() != 0 ? memoryMXBean.getHeapMemoryUsage().getInit() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setUsedKb(memoryMXBean.getHeapMemoryUsage().getUsed() != 0 ? memoryMXBean.getHeapMemoryUsage().getUsed() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setMaxKb(memoryMXBean.getHeapMemoryUsage().getMax() != 0 ? memoryMXBean.getHeapMemoryUsage().getMax() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setCommitedKb(memoryMXBean.getHeapMemoryUsage().getCommitted() != 0 ? memoryMXBean.getHeapMemoryUsage().getCommitted() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus().setName("Non-Heap"); applicationStatus.getNonHeapMemoryStatus().setDetails(memoryMXBean.getNonHeapMemoryUsage().toString()); applicationStatus.getNonHeapMemoryStatus() .setInitKb(memoryMXBean.getNonHeapMemoryUsage().getInit() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getInit() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setUsedKb(memoryMXBean.getNonHeapMemoryUsage().getUsed() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getUsed() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setMaxKb(memoryMXBean.getNonHeapMemoryUsage().getMax() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getMax() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setCommitedKb(memoryMXBean.getNonHeapMemoryUsage().getCommitted() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getCommitted() / 1024 : 0); applicationStatus.setLiveThreadCount(threadMXBean.getThreadCount()); applicationStatus.setTotalThreadCount(threadMXBean.getTotalStartedThreadCount()); applicationStatus.setStartTime(new Date(runtimeMXBean.getStartTime())); applicationStatus.setUpTime(TimeUtil.millisToString(runtimeMXBean.getUptime())); for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { applicationStatus.getGarbageCollectionInfos() .add(TimeUtil.millisToString(garbageCollectorMXBean.getCollectionTime()) + " - (" + garbageCollectorMXBean.getCollectionCount() + ")"); } for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) { MemoryPoolStatus memoryPoolStatus = new MemoryPoolStatus(); memoryPoolStatus.setName(memoryPoolMXBean.getName() + " - " + memoryPoolMXBean.getType()); memoryPoolStatus.setDetails(memoryPoolMXBean.getUsage().toString()); memoryPoolStatus.setInitKb( memoryPoolMXBean.getUsage().getInit() != 0 ? memoryPoolMXBean.getUsage().getInit() / 1024 : 0); memoryPoolStatus.setUsedKb( memoryPoolMXBean.getUsage().getUsed() != 0 ? memoryPoolMXBean.getUsage().getUsed() / 1024 : 0); memoryPoolStatus.setMaxKb( memoryPoolMXBean.getUsage().getMax() != 0 ? memoryPoolMXBean.getUsage().getMax() / 1024 : 0); memoryPoolStatus.setCommitedKb(memoryPoolMXBean.getUsage().getCommitted() != 0 ? memoryPoolMXBean.getUsage().getCommitted() / 1024 : 0); applicationStatus.getMemoryPools().add(memoryPoolStatus); } return sendSingleEntityResponse(applicationStatus); }