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


Java ThreadMXBean.getCurrentThreadCpuTime方法代码示例

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


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

示例1: getCpuTime

import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
/** Get CPU time in nanoseconds. */

private long getCpuTime( ) {
	ThreadMXBean bean = null;
	try {
		bean = ManagementFactory.getThreadMXBean( );
	} catch (Error e) {
		// not supported (happens in the by means of IKVM converted version (.net)
		return 0L;
	}
	return bean.isCurrentThreadCpuTimeSupported( ) ?
        bean.getCurrentThreadCpuTime( ) : 0L;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:14,代码来源:OdaTiming.java

示例2: thePathOfFifteenThousandJumps

import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
@Test
public void thePathOfFifteenThousandJumps() {
    byte[] bytecode = new byte[15000 * 6 + 3];

    int k = 0;

    while (k < 15000 * 6) {
        int target = k + 6;
        bytecode[k++] = 0x5b; // JUMPDEST
        bytecode[k++] = 0x62; // PUSH3
        bytecode[k++] = (byte)(target >> 16);
        bytecode[k++] = (byte)(target >> 8);
        bytecode[k++] = (byte)(target & 0xff);
        bytecode[k++] = 0x56; // JUMP
    }

    bytecode[k++] = 0x5b; // JUMPDEST
    bytecode[k++] = 0x60; // PUSH1
    bytecode[k++] = 0x01; // 1

    ThreadMXBean thread = ManagementFactory.getThreadMXBean();

    Runtime runtime = Runtime.getRuntime();
    runtime.gc();
    long initialMemory = runtime.totalMemory() - runtime.freeMemory();
    long initialTime = thread.getCurrentThreadCpuTime();
    testCode(bytecode, 15000 * 3 + 2, "0000000000000000000000000000000000000000000000000000000000000001");
    long finalTime = thread.getCurrentThreadCpuTime();
    long finalMemory = runtime.totalMemory() - runtime.freeMemory();

    System.out.println(String.format("Execution Time %s nanoseconds", finalTime - initialTime));
    System.out.println(String.format("Delta memory %s", finalMemory - initialMemory));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:34,代码来源:VMExecutionTest.java

示例3: spin

import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
/**
 * Actively spins the current thread for at least a given number of milliseconds in such a way
 * that timers for the current thread keep ticking over.
 *
 * @return the number of milliseconds actually spent spinning which is guaranteed to be >=
 *         {@code ms}
 */
private static long spin(long ms) {
    ThreadMXBean threadMXBean = Management.getThreadMXBean();
    long start = threadMXBean.getCurrentThreadCpuTime();
    do {
        long durationMS = (threadMXBean.getCurrentThreadCpuTime() - start) / 1000;
        if (durationMS >= ms) {
            return durationMS;
        }
    } while (true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TimerKeyTest.java


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