For a particular segment of Java code, I\'d like to measure:
With the ThreadMXBean you can get CPU usage of individual threads and cpu time consumed rather than elapse time which may be useful.
However, its often simpler to use a profiler as this process often generates a lot of data and you need a good visualisation tool to see what is going on.
I use Yourkit as I find it easier to solve problems that other profilers I have used. I also use the builtin hprof as this can give you a different view on the profile of your application (but not as useful)