我有一个场景,我希望一个线程睡眠特定的时间.
码:
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?
}
}
Run Code Online (Sandbox Code Playgroud)
现在我如何处理我试图运行的线程在完成睡眠之前被中断的异常命中的情况?线程在被中断后唤醒并且它是否进入可运行状态,或者只有在它进入runnable之后它才会进入catch块?