Rur*_*ano 6 java multithreading
我想知道我怎么知道一个线程是否正在睡觉.我搜索了一下,我收集了一些信息,形成了我写的一个方法 isSleeping():boolean 我认为我可以在一个类中确定线程是否正在休眠.我只是想知道我可能错过了什么.注意:我没有经验0天的经验.
//isSleeping returns true if this thread is sleeping and false otherwise.
public boolean isSleeping(){
boolean state = false;
StackTraceElement[] threadsStackTrace = this.getStackTrace();
if(threadsStackTrace.length==0){
state = false;
}
if(threadsStackTrace[0].getClassName().equals("java.lang.Thread")&&
threadsStackTrace[0].getMethodName().equals("Sleep")){
state = true;
}
return state;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1810 次 |
| 最近记录: |