Skip to content
System.currentTimeMillis()
will only ever measure wall-clock time, never CPU time.
- If you need wall-clock time, then
System.nanoTime()
is often more precise (and never worse) than currentTimeMillis()
.
ThreadMXBean.getThreadCPUTime()
can help you find out how much CPU time a given thread has used. Use ManagementFactory.getThreadMXBean()
to get a ThreadMXBean
and Thread.getId()
to find the id
of the thread you’re interested in. Note that this method need not be supported on every JVM!