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

Java examples for java.lang.management:MemoryMXBean

Description

Get system 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 system time in nanoseconds. */
    public static long getSystemTime() {
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();
        return bean.isCurrentThreadCpuTimeSupported() ? (bean
                .getCurrentThreadCpuTime() - bean
                .getCurrentThreadUserTime()) : 0L;
    }//from   w  w  w  .j  a  v a 2  s.  c  om
}

Related Tutorials