如何检查线程是否正在休眠? [英] How to check if a thread is sleeping?

查看:83
本文介绍了如何检查线程是否正在休眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以检查给定线程是否正在休眠?

Is there any way to check if a given thread is sleeping?

推荐答案

您可以调用

You can call Thread.getState() on and check if the state is TIMED_WAITING.

请注意,但是TIMED_WAITING不一定表示名为

Note, however that TIMED_WAITING doesn't necessarily mean that the thread called sleep(), it could also be waiting in a Object.wait(long) call or something similar.

这篇关于如何检查线程是否正在休眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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