agentBrown
Programmer
For an application I'm writing, I would like to keep tabs on how much CPU power the various threads are taking up. However, I do not see a suitable method in either java.lang.Thread or java.lang.ThreadGroup that gives such information.
Is there a way to find CPU load for each Thread?
If not, I was thinking of overriding Thread.sleep and such to time threads myself. When I start a thread, make a timestamp. When the thread exits, make another timestamp. That would work except to be 'fair' to the threadcode I need to filter out the time that the thread was in 'sleep' mode, either through Thread.sleep, Thread.yield, or one of the blocking java.io or java.net functions. One way of doing this is timestamping right before and right after a sleep/yield (and perhaps I can find out a way to timestamp time spent in blocking IO/net code).
However, will this kind of thing work: (pseudoish)
wil this method be called instead of the one in java.lang.Thread, when I create a StampingThread, and use Thread.yield() in the code that will be run by the StampingThread?
Is there a way to find CPU load for each Thread?
If not, I was thinking of overriding Thread.sleep and such to time threads myself. When I start a thread, make a timestamp. When the thread exits, make another timestamp. That would work except to be 'fair' to the threadcode I need to filter out the time that the thread was in 'sleep' mode, either through Thread.sleep, Thread.yield, or one of the blocking java.io or java.net functions. One way of doing this is timestamping right before and right after a sleep/yield (and perhaps I can find out a way to timestamp time spent in blocking IO/net code).
However, will this kind of thing work: (pseudoish)
Code:
public class StampingThread
extends Thread {
public static void yield() {
long timestamp = currentTime;
Thread.yield();
long inactiveTime = currentTime - timestamp;
}
}
wil this method be called instead of the one in java.lang.Thread, when I create a StampingThread, and use Thread.yield() in the code that will be run by the StampingThread?