private long cpuTime ( Thread thr ) { ThreadMXBean mxBean = ManagementFactory . getThreadMXBean ( ) ; if ( mxBean . isThreadCpuTimeSupported ( ) ) { try { return mxBean . getThreadCpuTime ( thr . getId ( ) ) ; } catch ( UnsupportedOperationException e ) { } } return 0 ; }
Returns the CPU time used by a thread if possible .