how to measure running time of a thread?
hello,
is it possible to measure the running time of a specific thread, instead of measuring the running time (via System.currentTimeMillis ()) of the whole program?
What i need, is the time of a thread on the cpu.
What i don't need is something like this:
...
Thread t =new Thread ();
begin = System.currentTimeMillis ();
t.start ();
t.join ();
System.out.println (System.currentTimeMillis () - begin);
...
and this:
...
publicvoid run ()
{
long end;
long runningTimeOfThread;
long begin;
begin = System.currentTimeMillis ();
//do some time consuming work
end = System.currentTimeMillis ();
runningTimeOfThread = end - begin;
}
...
what i need is something like this (or something equivalent):
...
publicvoid run ()
{
long end;
long runningTimeOfThread;
long begin;
begin = measureRunningTimeOfThisThread ();
//do some time consuming work
end = measureRunningTimeOfThisThread ();
runningTimeOfThread = end - begin;
}
tnx in advance
mamurdian
[1704 byte] By [
mamurdiana] at [2007-10-3 11:04:24]

public void run ()
{
long end;
long runningTimeOfThread;
long begin;
begin = measureRunningTimeOfThisThread ();
while(!theEndOfWork){
System.out.println("Take a cup of coffee");
}
end = measureRunningTimeOfThisThread ();
runningTimeOfThread = end - begin;
}
Mithua at 2007-7-15 13:26:51 >

> >
> public void run ()
> {
> long end;
> long runningTimeOfThread;
> long begin;
>
> begin = measureRunningTimeOfThisThread ();
>
> while(!theEndOfWork){
> System.out.println("Take a cup of coffee");
>}
> = measureRunningTimeOfThisThread ();
>
> runningTimeOfThread = end - begin;
> }
>
>
i'm not sure if i understand your post correctly, but if it is was your intention to tell me that i can use a while loop instead of my initial java comment, i think you have misunderstood me.
measureRunningTimeOfThisThread () is not a "real" method. It is only placeholder that i used to emphasize my requirement. What i need is a replacement for measureRunningTimeOfThisThread ().
greets
mamurdian
Perhaps the code snippet should something like...
public void run ()
{
long runningTimeOfThread;
while(!theEndOfWork){
System.out.println("Take a cup of coffee");
}
runningTimeOfThread = ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime();
}
" runningTimeOfThread" indicating the value used by the current thread..