Get running time of a thread java
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
精彩评论