Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get running time of a thread java

Tags:

java

How can I get the runtime a thread in java such as: 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.

like image 887
Cyril D. Avatar asked Sep 01 '11 20:09

Cyril D.


1 Answers

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.

like image 164
Bozho Avatar answered Oct 07 '22 01:10

Bozho