27 September 2019

JVM CPU

Thread CPU time

A Java virtual machine implementation may support measuring the CPU time for the current thread, for any thread, or for no threads.The isThreadCpuTimeSupported() method can be used to determine if a Java virtual machine supports measuring of the CPU time for any thread. The isCurrentThreadCpuTimeSupported() method can be used to determine if a Java virtual machine supports measuring of the CPU time for the current thread. A Java virtual machine implementation that supports CPU time measurement for any thread will also support that for the current thread.
The CPU time provided by this interface has nanosecond precision but not necessarily nanosecond accuracy.
A Java virtual machine may disable CPU time measurement by default. The isThreadCpuTimeEnabled() and setThreadCpuTimeEnabled(boolean) methods can be used to test if CPU time measurement is enabled and to enable/disable this support respectively. Enabling thread CPU measurement could be expensive in some Java virtual machine implementations.

https://docs.oracle.com/javase/7/docs/api/java/lang/management/ThreadMXBean.html#getThreadCpuTime(long)


ThreadMXBean.getThreadCpuTime()

https://github.com/devwebcl/jdk7u-jdk/blob/master/src/share/classes/java/lang/management/ThreadMXBean.java


https://github.com/devwebcl/jdk7u-jdk/blob/master/src/share/classes/sun/management/ThreadImpl.java


No comments :

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.