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


Java ThreadMXBean.getAllThreadIds方法代码示例

本文整理汇总了Java中com.sun.management.ThreadMXBean.getAllThreadIds方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadMXBean.getAllThreadIds方法的具体用法?Java ThreadMXBean.getAllThreadIds怎么用?Java ThreadMXBean.getAllThreadIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.management.ThreadMXBean的用法示例。


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

示例1: run

import com.sun.management.ThreadMXBean; //导入方法依赖的package包/类
@Override
public void run() {
    while (!isInterrupted()) {
        ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
        for (long threadId : threadMXBean.getAllThreadIds()) {
            ThreadInfo info = threadMXBean.getThreadInfo(threadId);
            ThreadPrevValues prevValues = getPrevValues(threadId);
            long cpuTime = threadMXBean.getThreadCpuTime(threadId);
            long allocatedBytes = threadMXBean.getThreadAllocatedBytes(threadId);

            System.out.println(info.getThreadName() +
                " CPU time: " + prevValues.getDeltaCPUTime(cpuTime)  +
                " Allocated bytes: " + prevValues.getDeltaBytes(allocatedBytes));

            prevValues.update(cpuTime, allocatedBytes);
        }

        delaySleep();
    }

    System.out.println("ThreadStateLogger stopped");
}
 
开发者ID:kslisenko,项目名称:java-performance,代码行数:23,代码来源:ThreadStateLogger.java

示例2: main

import com.sun.management.ThreadMXBean; //导入方法依赖的package包/类
public static void main(String[] args) {
    System.out.println("Threads");
    ThreadMXBean threadMBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();

    System.out.println("Thread count = " + threadMBean.getThreadCount());
    System.out.println("Thread IDs = " + Arrays.toString(threadMBean.getAllThreadIds()));

    System.out.println(">>>>> Thread INFO");
    ThreadInfo[] threads = threadMBean.dumpAllThreads(true, true);
    for (ThreadInfo thread : threads) {
        System.out.println(thread);
    }

    System.out.println(">>>>> Thread INFO detailed");
    for (long threadId : threadMBean.getAllThreadIds()) {
        ThreadInfo threadInfo = threadMBean.getThreadInfo(threadId, 100);
        long cpuTime = threadMBean.getThreadCpuTime(threadId);
        long userTime = threadMBean.getThreadUserTime(threadId);
        long allocatedBytes = threadMBean.getThreadAllocatedBytes(threadId);
        System.out.println(threadInfo);
        System.out.println("CPU Time: " + cpuTime + ", USER time: " + userTime + ", Allocated bytes: " + allocatedBytes);
    }

    // Getting stack-traces of the current thread
    System.out.print(">> current thread: " + Thread.currentThread().getName() + "\n");
    for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
        System.out.println(element);
    }
}
 
开发者ID:kslisenko,项目名称:java-performance,代码行数:30,代码来源:Threads.java

示例3: baselineMemoryAllocation

import com.sun.management.ThreadMXBean; //导入方法依赖的package包/类
/**
 * Baselines amount of memory allocated by each thread.
 */
public void baselineMemoryAllocation() {
    ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
    threadIds = bean.getAllThreadIds();
    baselinedThreadMemoryUsage = bean.getThreadAllocatedBytes(threadIds);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:SurvivorAlignmentTestMain.java


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