开发者

delay between two threads in a java program

In a java program i have two different threads. How to calculate the delay between the execution of开发者_开发问答 the two different threads throughout the program?

Thank you


Use the System class's nanoTime()

Returns the current value of the most precise available system timer, in nanoseconds.

 long startTime = System.nanoTime();
 // ... the code being measured ...
 long estimatedTime = System.nanoTime() - startTime;

You can also use currentTimeMillis()

Returns the current time in milliseconds.


Assuming that the to threads perform execute the same code, you can calculate the delay using System.currentTimeMillis() and compare the time of the first and second thread for each program point you are interested in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜