当前位置: 首页>>代码示例>>Java>>正文


Java ThreadMXBean类代码示例

本文整理汇总了Java中java.lang.management.ThreadMXBean的典型用法代码示例。如果您正苦于以下问题:Java ThreadMXBean类的具体用法?Java ThreadMXBean怎么用?Java ThreadMXBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ThreadMXBean类属于java.lang.management包,在下文中一共展示了ThreadMXBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
public static void start() {
	if (started) throw new IllegalStateException("Already Started.");
	OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
	ThreadMXBean thread = ManagementFactory.getThreadMXBean();
	Runtime r = Runtime.getRuntime();
	int mb = 0x100000;

	lastSystemTime = System.nanoTime();
	lastProcessCpuTime = calculateProcessCpuTime(os);

	Async.task("AsyncInfoMonitorThread", () -> {
		threadCount = thread.getThreadCount();
		availableProcessors = r.availableProcessors();
		freeMemory = Runtime.getRuntime().freeMemory() / mb;
		maxMemory = Runtime.getRuntime().maxMemory() / mb;
		totalMemory = Runtime.getRuntime().totalMemory() / mb;
		cpuUsage = calculateCpuUsage(os);
		vpsCPUUsage = getVpsCPUUsage(os);
		vpsFreeMemory = calculateVPSFreeMemory(os);
		vpsMaxMemory = calculateVPSMaxMemory(os);
		vpsUsedMemory = vpsMaxMemory - vpsFreeMemory;
	}, 1);
	started = true;
}
 
开发者ID:Mantaro,项目名称:MantaroRPG,代码行数:25,代码来源:AsyncInfoMonitor.java

示例2: render

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
@Override
protected void render(Block html) {
  set(TITLE, join("Angel ExecutorsBlock"));
  TBODY<TABLE<Hamlet>> tbody =
      html.h1("ExecutorsBlock").table("#jobs").thead().tr().th(_TH, "id").th(_TH, "name")
          .th(_TH, "state").th(_TH, "stacktrace")._()._().tbody();

  ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
  ThreadInfo[] threadInfo = threadMXBean.dumpAllThreads(true, true);
  StringBuilder stackTraceString;
  for (ThreadInfo t : threadInfo) {
    stackTraceString = new StringBuilder();
    StackTraceElement[] stackTrace = t.getStackTrace();
    for (StackTraceElement s : stackTrace) {
      stackTraceString.append(s.toString()).append("\n");
    }
    tbody.tr().td(String.valueOf(t.getThreadId())).td(String.valueOf(t.getThreadName()))
        .td(String.valueOf(t.getThreadState())).td(String.valueOf(stackTraceString.toString()))._();
  }
  tbody._()._();


}
 
开发者ID:Tencent,项目名称:angel,代码行数:24,代码来源:ExecutorsBlock.java

示例3: getThreadStack

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
/**
 * Gets thread stack.
 *
 * @return the thread stack
 */
private String getThreadStack()
{
  ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
  ThreadInfo[] threadInfo =  threadMXBean.dumpAllThreads(true, true);
  StringBuilder stackTraceString= new StringBuilder("ParameterServer\n");
  StringBuilder infoBlock= new StringBuilder("\n");
  for(ThreadInfo t :  threadInfo)
  {
    infoBlock = new StringBuilder("\n\n");
    infoBlock.append("threadid: ").append(t.getThreadId()).append(" threadname: ").append(t.getThreadName()).append("       threadstate: ").append(t.getThreadState()).append("\n");
    for(StackTraceElement stackTraceElement : t.getStackTrace())
    {
      infoBlock.append("   ").append(stackTraceElement.toString()).append("\n");
    }
    stackTraceString.append(infoBlock).append("\n\n");
  }
  return stackTraceString.toString();
}
 
开发者ID:Tencent,项目名称:angel,代码行数:24,代码来源:ParameterServerService.java

示例4: call

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
@Override
public String call() {
  Map<String, String> memoryMap = new HashMap<>();
  OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
  double cpu = osMxBean.getSystemLoadAverage();
  memoryMap.put("cpuLoad", String.format(doubleStringFormatter, round(cpu, doubleRoundPlaces)));

  ThreadMXBean threadmxBean = ManagementFactory.getThreadMXBean();
  int threadCount = threadmxBean.getThreadCount();
  memoryMap.put("cpuRunningThreads", String.valueOf(threadCount));

  MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
  MemoryUsage memHeapUsage = memBean.getHeapMemoryUsage();
  MemoryUsage nonHeapUsage = memBean.getNonHeapMemoryUsage();
  memoryMap.put("heapInit", String.valueOf(memHeapUsage.getInit()));
  memoryMap.put("heapMax", String.valueOf(memHeapUsage.getMax()));
  memoryMap.put("heapCommit", String.valueOf(memHeapUsage.getCommitted()));
  memoryMap.put("heapUsed", String.valueOf(memHeapUsage.getUsed()));
  memoryMap.put("nonHeapInit", String.valueOf(nonHeapUsage.getInit()));
  memoryMap.put("nonHeapMax", String.valueOf(nonHeapUsage.getMax()));
  memoryMap.put("nonHeapCommit", String.valueOf(nonHeapUsage.getCommitted()));
  memoryMap.put("nonHeapUsed", String.valueOf(nonHeapUsage.getUsed()));
  return memoryMap.toString();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:MetricsServoRegistry.java

示例5: sense

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
@Override
public void sense(final MetricRecorder.Context 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();
}
 
开发者ID:awslabs,项目名称:swage,代码行数:19,代码来源:ThreadSensor.java

示例6: testReset

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
@Test
public void testReset() {
    System.out.println("reset");
    ThreadMXBean tbean = ManagementFactory.getThreadMXBean();
    addStacktrace(tbean.getThreadInfo(tbean.getAllThreadIds(), Integer.MAX_VALUE), System.nanoTime());
    addStacktrace(tbean.getThreadInfo(tbean.getAllThreadIds(), Integer.MAX_VALUE), System.nanoTime());

    instance.reset();
    assertTrue(instance.methodInfos.size()-1 == 0);
    assertTrue(instance.threadIds.size() == 0);
    assertTrue(instance.threadNames.size() == 0);
    assertEquals(-1L, instance.currentDumpTimeStamp);
    //assertEquals(-1L, instance.firstDumpTimeStamp);
    assertEquals(0, instance.stackTraceCount);

    try {
        instance.createSnapshot(System.currentTimeMillis());
        fail();
    } catch (CPUResultsSnapshot.NoDataAvailableException ex) {
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:StackTraceSnapshotBuilderTest.java

示例7: countTimerThreads

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
private static int countTimerThreads() {
  ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
  
  int count = 0;
  ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
  for (ThreadInfo info : infos) {
    if (info == null) continue;
    for (StackTraceElement elem : info.getStackTrace()) {
      if (elem.getClassName().contains("Timer")) {
        count++;
        break;
      }
    }
  }
  return count;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:TestShell.java

示例8: buildDeadlockInfo

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
static String buildDeadlockInfo() {
  ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
  long[] threadIds = threadBean.findMonitorDeadlockedThreads();
  if (threadIds != null && threadIds.length > 0) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter out = new PrintWriter(stringWriter);
    
    ThreadInfo[] infos = threadBean.getThreadInfo(threadIds, true, true);
    for (ThreadInfo ti : infos) {
      printThreadInfo(ti, out);
      printLockInfo(ti.getLockedSynchronizers(), out);
      out.println();
    }
    
    out.close();
    return stringWriter.toString();
  } else {
    return null;
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:TimedOutTestsListener.java

示例9: countThreads

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
/**
 * Count the number of threads that have a stack frame containing
 * the given string
 */
protected static int countThreads(String search) {
  ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

  int count = 0;
  ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
  for (ThreadInfo info : infos) {
    if (info == null) continue;
    for (StackTraceElement elem : info.getStackTrace()) {
      if (elem.getClassName().contains(search)) {
        count++;
        break;
      }
    }
  }
  return count;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:TestRpcBase.java

示例10: getAllThreadInfo

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
public static List<TInfo> getAllThreadInfo(){

        List<TInfo> threads = new ArrayList<>();
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        long[] ids = threadBean.getAllThreadIds();
        ThreadInfo[] infos = threadBean.getThreadInfo(ids);
        for (ThreadInfo info : infos){
            long id = info.getThreadId();
            TInfo tInfo = new TInfo();
            tInfo.name = info.getThreadName();
            tInfo.id = id;
            tInfo.state = info.getThreadState();
            tInfo.cpuTime = threadBean.getThreadCpuTime(id);
            threads.add(tInfo);
        }
        Collections.sort(threads,new Comparator<TInfo>() {
            @Override
            public int compare(TInfo o1, TInfo o2) {
                return Long.compare(o2.cpuTime,o1.cpuTime);
            }
        });
        return threads;
    }
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:24,代码来源:ThreadingManager.java

示例11: dump

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
public static ThreadInfo[] dump(int maxDepth,boolean onlyDeadLock){
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

    long[] ids ;
    if(onlyDeadLock) {
        ids = threadBean.findDeadlockedThreads();
    }else {
       ids = threadBean.getAllThreadIds();
    }
    if(ids !=null) {
        return threadBean.getThreadInfo(ids, maxDepth);
    }
    else {
        return null;
    }


}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:19,代码来源:ThreadingManager.java

示例12: bindTo

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
@Override
public void bindTo(MeterRegistry registry) {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

    Gauge.builder("jvm.threads.peak", threadBean, ThreadMXBean::getPeakThreadCount)
        .tags(tags)
        .description("The peak live thread count since the Java virtual machine started or peak was reset")
        .register(registry);

    Gauge.builder("jvm.threads.daemon", threadBean, ThreadMXBean::getDaemonThreadCount)
        .tags(tags)
        .description("The current number of live daemon threads")
        .register(registry);

    Gauge.builder("jvm.threads.live", threadBean, ThreadMXBean::getThreadCount)
        .tags(tags)
        .description("The current number of live threads including both daemon and non-daemon threads")
        .register(registry);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:20,代码来源:JvmThreadMetrics.java

示例13: getAllThreadIDsExceptMain

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
/**
 * @return Set of the IDs of all threads that are started except the "main" thread.
 */
public Set<Long> getAllThreadIDsExceptMain() {

    ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
    // get the IDs of all live threads.
    long[] threadIDs = thbean.getAllThreadIds();
    Set<Long> res = new HashSet<Long>();

    // get the IDs of all threads except main
    for (long id : threadIDs) {
        Thread t = getThread(id);
        if (t != null && !"main".equals(t.getName())) {
            res.add(id);
        }
    }

    return res;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:21,代码来源:ThreadUtils.java

示例14: getAllThreads

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:26,代码来源:ThreadUtils.java

示例15: start

import java.lang.management.ThreadMXBean; //导入依赖的package包/类
public static void start() {
    if (started) throw new IllegalStateException("Already Started.");
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    ThreadMXBean thread = ManagementFactory.getThreadMXBean();
    Runtime r = Runtime.getRuntime();
    int mb = 0x100000;

    lastSystemTime = System.nanoTime();
    lastProcessCpuTime = calculateProcessCpuTime(os);

    Async.task("AsyncInfoMonitorThread", () -> {
        threadCount = thread.getThreadCount();
        availableProcessors = r.availableProcessors();
        freeMemory = Runtime.getRuntime().freeMemory() / mb;
        maxMemory = Runtime.getRuntime().maxMemory() / mb;
        totalMemory = Runtime.getRuntime().totalMemory() / mb;
        cpuUsage = calculateCpuUsage(os);
        vpsCPUUsage = getVpsCPUUsage(os);
        vpsFreeMemory = calculateVPSFreeMemory(os);
        vpsMaxMemory = calculateVPSMaxMemory(os);
        vpsUsedMemory = vpsMaxMemory - vpsFreeMemory;
    }, 1);
    started = true;
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:25,代码来源:AsyncInfoMonitor.java


注:本文中的java.lang.management.ThreadMXBean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。