如何测量线程等待时间? [英] How can I measure thread waiting time?

查看:635
本文介绍了如何测量线程等待时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到如何测量线程等待锁定的时间.我必须确定一个线程是否正在等待锁定超过1秒,如果是,则运行另一个线程.谢谢!

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 Thread instead. Thanks!

推荐答案

尝试一下:

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

long duration = endTime - startTime;

这篇关于如何测量线程等待时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆