Java Code Examples for java.lang.management.ThreadMXBean#getPeakThreadCount()

The following examples show how to use java.lang.management.ThreadMXBean#getPeakThreadCount() . 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: ThreadsIterator.java    From Bats with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ThreadSensor.java    From swage with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: MonitoredDataImpl.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
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 4
Source File: ThreadsStatusSampler.java    From kieker with Apache License 2.0 5 votes vote down vote up
@Override
protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName,
		final IMonitoringController monitoringCtr) {
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMThreadsSignature())) {
		return new IMonitoringRecord[] {};
	}

	final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

	return new IMonitoringRecord[] { new ThreadsStatusRecord(timestamp, hostname, vmName, threadBean.getThreadCount(), threadBean.getDaemonThreadCount(),
			threadBean.getPeakThreadCount(), threadBean.getTotalStartedThreadCount()), };
}
 
Example 5
Source File: JmxInfoProviderSupport.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public int getPeakThreadCount() {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    return threadMXBean.getPeakThreadCount();
}
 
Example 6
Source File: JavaInformations.java    From javamelody with Apache License 2.0 4 votes vote down vote up
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;
	}
}