ThreadcurrentThread=Thread.currentThread();publicvoidrun(){while(!shutdown){try{System.out.println(currentThread.isAlive());Thread.interrupted();System.out.println(currentThread.isAlive());if(currentThread.isAlive()==false){shutdown=true;}}catch(Exceptione){currentThread.interrupt();}}}});thread
Java的Thread.sleep什么时候抛出InterruptedException?忽略它是否安全?我没有做任何多线程。我只想等待几秒钟再重试一些操作。 最佳答案 您通常不应忽略该异常。请看以下论文:Don'tswallowinterruptsSometimesthrowingInterruptedExceptionisnotanoption,suchaswhenataskdefinedbyRunnablecallsaninterruptiblemethod.Inthiscase,youcan'trethrowInterrupt
Java的Thread.sleep什么时候抛出InterruptedException?忽略它是否安全?我没有做任何多线程。我只想等待几秒钟再重试一些操作。 最佳答案 您通常不应忽略该异常。请看以下论文:Don'tswallowinterruptsSometimesthrowingInterruptedExceptionisnotanoption,suchaswhenataskdefinedbyRunnablecallsaninterruptiblemethod.Inthiscase,youcan'trethrowInterrupt