本文整理汇总了Java中com.sun.management.ThreadMXBean.getThreadAllocatedBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadMXBean.getThreadAllocatedBytes方法的具体用法?Java ThreadMXBean.getThreadAllocatedBytes怎么用?Java ThreadMXBean.getThreadAllocatedBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.management.ThreadMXBean
的用法示例。
在下文中一共展示了ThreadMXBean.getThreadAllocatedBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: areOtherThreadsAllocatedMemory
import com.sun.management.ThreadMXBean; //导入方法依赖的package包/类
/**
* Checks if threads other then the current thread were allocating objects
* after baselinedThreadMemoryUsage call.
*
* If baselinedThreadMemoryUsage was not called, then this method will return
* {@code false}.
*/
public boolean areOtherThreadsAllocatedMemory() {
if (baselinedThreadMemoryUsage == null) {
return false;
}
ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
long currentMemoryAllocation[]
= bean.getThreadAllocatedBytes(threadIds);
boolean otherThreadsAllocatedMemory = false;
System.out.println("Verifying amount of memory allocated by threads:");
for (int i = 0; i < threadIds.length; i++) {
System.out.format("Thread %d%nbaseline allocation: %d"
+ "%ncurrent allocation:%d%n", threadIds[i],
baselinedThreadMemoryUsage[i], currentMemoryAllocation[i]);
System.out.println(bean.getThreadInfo(threadIds[i]));
long bytesAllocated = Math.abs(currentMemoryAllocation[i]
- baselinedThreadMemoryUsage[i]);
if (bytesAllocated > 0
&& threadIds[i] != Thread.currentThread().getId()) {
otherThreadsAllocatedMemory = true;
}
}
return otherThreadsAllocatedMemory;
}
示例3: 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);
}
}
示例4: getThreadAllocatedBytes
import com.sun.management.ThreadMXBean; //导入方法依赖的package包/类
private static long getThreadAllocatedBytes() {
ThreadMXBean thread = (ThreadMXBean) ManagementFactory.getThreadMXBean();
return thread.getThreadAllocatedBytes(currentThread().getId());
}
示例5: 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);
}
示例6: getThreadAllocatedBytes
import com.sun.management.ThreadMXBean; //导入方法依赖的package包/类
private static long getThreadAllocatedBytes() {
ThreadMXBean thread = (ThreadMXBean) Management.getThreadMXBean();
return thread.getThreadAllocatedBytes(currentThread().getId());
}