Accurately Calculating the time a Thread takes to run

How do I accurately gain timings for a thread? I have a number of threads which are calling CalculatorEngine which locks on an object starts a timer (ctime = System.currentTimeMillis();) and then logs the time just before the thread exits

System.out.println("Calculations for " + setName + " for " + calcsMadeByCalcEnginge + " positions took: " + (System.currentTimeMillis() - ctime));

But if there is a context swich my timer will continue to run until the thread is reactivated and then completes... How can I gain the actual timings for how long the thread took?

[585 byte] By [java_swing_dudea] at [2007-11-27 11:44:43]
# 1

> How do I accurately gain timings for a thread?

You can't.

>

> But if there is a context swich my timer will

> continue to run until the thread is reactivated and

> then completes...

Correct.

> How can I gain the actual timings

> for how long the thread took?

You can't. As I said and as you already pointed out why.

Not to mention that on modern OSes threads in other apps might steal time as well.

You can just run it in a loop, make sure no other resource hungry apps are running and then estimate the time taken.

jschella at 2007-7-29 17:57:27 > top of Java-index,Java Essentials,Java Programming...