本文介绍了如何检查线程是否正在休眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以检查给定线程是否正在休眠?
Is there any way to check if a given thread is sleeping?
推荐答案
您可以调用 Thread.getState()
并检查状态是否为 TIMED_WAITING
.
You can call Thread.getState()
on and check if the state is TIMED_WAITING
.
请注意,但是TIMED_WAITING
不一定表示名为 sleep()
,它也可能在 Object.wait(long)
调用或类似的命令.
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.
这篇关于如何检查线程是否正在休眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!