开发者

Get running time of a thread java

开发者 https://www.devze.com 2023-04-01 04:08 出处:网络
How can I get the runtime a thread in java such a开发者_如何学Cs: at 00:30 minutes of Thread[n], something() happened.

How can I get the runtime a thread in java such a开发者_如何学Cs: at 00:30 minutes of Thread[n], something() happened.

I'm basically looking to make a log file for a program dealing with audio files.

Thank you.


You can get the System.nanoTime() in the beginning and then calculate the difference at the end. Then use TimeUnit to convert to a more useful unit.

Also check the ThreadMXBean which is an MBean giving info about threads.


Otherwise you can use System.currentTimeMillis() Function to get the current time in milliseconds instead of nanos and then subtract to get the elapsed time

0

精彩评论

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