A few of you have raised (valid) concerns about Process.times not
accurately representing the actual CPU usage. This is of course
true…currently it is implemented as a clock time counter from startup,
since under Java 1.4 there was no was way for us to get at real CPU
However, we have two options now that can fix this.
The first is to make a native call to the OS times(3) function which
will return the same structure MRI uses. This would only work when
native calls are allowed, which is perhaps good enough.
The second is to use the ThreadMXBean introduced in Java 5 to get thread
CPU tallies. There does not appear to be a way to get full-process CPU
counts, but it’s simple to get CPU counts on a per-thread basis. For
tmx = java.lang.management.ManagementFactory.thread_mxbean
a = 0; a += 1 while a < 10_000_000
This is of course already available. The full docs for the ThreadMXBean
Not being able to get full-process counts is a bit of a bother, but the
ability to do per-thread counts is pretty cool. Also check out the other
MXBeans in that package for information on memory, GC, and so on.
We’ll have the native “times” in 1.1.6, and you can use the ThreadMXBean
To unsubscribe from this list, please visit: