How can I measure thread waiting time?

后端 未结 3 1051
面向向阳花
面向向阳花 2021-01-19 08:14

I couldn\'t find out how to measure the time that a Thread is waiting locked. I have to determine if a Thread is waiting locked more than 1 second and if so to run another T

3条回答
  •  天涯浪人
    2021-01-19 08:50

    Try this:

    long startTime = System.nanoTime();
    methodToTime();
    long endTime = System.nanoTime();
    
    long duration = endTime - startTime;
    

提交回复
热议问题