Get CPU time in nanoseconds via Management bean - Java java.lang.management

Java examples for java.lang.management:MemoryMXBean

Description

Get CPU time in nanoseconds via Management bean

Demo Code


//package com.java2s;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;

public class Main {
    /** Get CPU time in nanoseconds. */
    public static long getCpuTime() {
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();
        return bean.isCurrentThreadCpuTimeSupported() ? bean
                .getCurrentThreadCpuTime() : 0L;
    }/*w  ww . ja  v  a2 s.c o  m*/
}

Related Tutorials