當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。