本文整理汇总了Java中com.sun.management.ThreadMXBean类的典型用法代码示例。如果您正苦于以下问题:Java ThreadMXBean类的具体用法?Java ThreadMXBean怎么用?Java ThreadMXBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThreadMXBean类属于com.sun.management包,在下文中一共展示了ThreadMXBean类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: getThreadMxBean
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
private ThreadMXBean getThreadMxBean()
{
if (ProcessingValve.threadMxBean == null)
{
ThreadMXBean tmxBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
if (!tmxBean.isCurrentThreadCpuTimeSupported())
{
throw new UnsupportedOperationException("Thread CPU monitoring not supported.");
}
if (tmxBean.isThreadCpuTimeSupported() && !tmxBean.isThreadCpuTimeEnabled())
{
tmxBean.setThreadCpuTimeEnabled(true);
}
if (tmxBean.isThreadAllocatedMemorySupported() && !tmxBean.isThreadAllocatedMemoryEnabled())
{
tmxBean.setThreadAllocatedMemoryEnabled(true);
}
ProcessingValve.threadMxBean = tmxBean;
}
return ProcessingValve.threadMxBean;
}
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:23,代码来源:ProcessingValve.java
示例3: setSession
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
/**
* Set the session for the thread.
* @param session Service session.
*/
public final void setSession(ServiceSession session) {
if(this.session != null) {
//Remove the status of the current thread stored into the old session
this.session.endThread();
}
if(session != null) {
//Start the status of the current thread into the new session.
session.startThread();
//Init the counters
setInitialAllocatedMemory(((ThreadMXBean)ManagementFactory.getThreadMXBean()).
getThreadAllocatedBytes(Thread.currentThread().getId()));
setInitialTime(ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime());
//Init the max allocated memory value for thread
configureMaxAllocatedMemory(SystemProperties.getLong(SystemProperties.Service.MAX_ALLOCATED_MEMORY_FOR_THREAD));
//Init the max execution time value for thread
configureMaxExecutionTime(SystemProperties.getLong(SystemProperties.Service.MAX_EXECUTION_TIME_FOR_THREAD));
}
this.session = session;
}
开发者ID:javaito,项目名称:HolandaCatalinaFw,代码行数:29,代码来源:ServiceThread.java
示例4: 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;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:SurvivorAlignmentTestMain.java
示例5: run
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
@Override
public void run() {
while (!isInterrupted()) {
ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
System.out.println(">>>>>>>>>>> Dumping threads");
ThreadInfo[] info = threadMXBean.dumpAllThreads(true, true);
System.out.println(Arrays.toString(info));
delaySleep();
}
System.out.println("ThreadSampler stopped");
}
开发者ID:kslisenko,项目名称:java-performance,代码行数:14,代码来源:ThreadSampler.java
示例6: 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
示例7: AllocationMonitor
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
public AllocationMonitor( final Thread benchmarkThread ) {
//noinspection SuspiciousToArrayCall
gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans().toArray( new GarbageCollectorMXBean[0] );
threadMXBean = ( ThreadMXBean ) ManagementFactory.getThreadMXBean();
this.benchmarkThreadId = benchmarkThread.getId();
}
开发者ID:cheremin,项目名称:scalarization,代码行数:8,代码来源:AllocationBenchmarkBuilder.java
示例8: checkAllocatedMemory
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
/**
* Verify if the current thread allocate more bytes that the max configured.
* @throws Throwable Throws a run time exception.
*/
public static void checkAllocatedMemory() throws Throwable {
ServiceThread serviceThread = (ServiceThread) Thread.currentThread();
if(serviceThread.getAccumulatedAllocatedMemory() > serviceThread.getMaxAllocatedMemory()) {
//Reset the initial value for the current thread in order to
//continue with the throwable handling
serviceThread.setInitialAllocatedMemory(((ThreadMXBean)ManagementFactory.getThreadMXBean()).
getThreadAllocatedBytes(Thread.currentThread().getId()));
throw new RuntimeException("Max memory allocated for thread exceeded");
}
}
开发者ID:javaito,项目名称:HolandaCatalinaFw,代码行数:17,代码来源:ServiceThread.java
示例9: getThreadAllocatedBytes
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
private static long getThreadAllocatedBytes() {
ThreadMXBean thread = (ThreadMXBean) ManagementFactory.getThreadMXBean();
return thread.getThreadAllocatedBytes(currentThread().getId());
}
开发者ID:arodchen,项目名称:MaxSim,代码行数:5,代码来源:CompilationStatistics.java
示例10: 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
示例11: getThreadAllocatedBytes
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
private static long getThreadAllocatedBytes() {
ThreadMXBean thread = (ThreadMXBean) Management.getThreadMXBean();
return thread.getThreadAllocatedBytes(currentThread().getId());
}
开发者ID:graalvm,项目名称:graal-core,代码行数:5,代码来源:CompilationStatistics.java
示例12: getAccumulatedAllocatedMemory
import com.sun.management.ThreadMXBean; //导入依赖的package包/类
public final Long getAccumulatedAllocatedMemory() {
return ((ThreadMXBean)ManagementFactory.getThreadMXBean()).
getThreadAllocatedBytes(Thread.currentThread().getId()) - getInitialAllocatedMemory();
}
开发者ID:javaito,项目名称:HolandaCatalinaFw,代码行数:5,代码来源:ServiceThread.java
注:本文中的com.sun.management.ThreadMXBean类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论