我有一个场景,想让线程睡眠一段特定的时间。
代码:
public void run(){
try{
//do something
Thread.sleep(3000);
//do something after waking up
}catch(InterruptedException e){
// interrupted exception hit before the sleep time is completed.so how do i make my thread sleep for exactly 3 seconds?
}
}
现在我该如何处理我尝试运行的线程在休眠完成之前遇到中断异常的情况?同时,当线程被中断后会醒来吗?它会进入可运行状态吗?还是只有在进入可运行状态后才会流向catch块?