本文整理汇总了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");
}
示例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);
}
}
示例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);
}