草庐IT

INTERRUPTION

全部标签

java - 我怎样才能杀死一个线程?不使用 stop();

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 - Java的Thread.sleep什么时候抛出InterruptedException?

Java的Thread.sleep什么时候抛出InterruptedException?忽略它是否安全?我没有做任何多线程。我只想等待几秒钟再重试一些操作。 最佳答案 您通常不应忽略该异常。请看以下论文:Don'tswallowinterruptsSometimesthrowingInterruptedExceptionisnotanoption,suchaswhenataskdefinedbyRunnablecallsaninterruptiblemethod.Inthiscase,youcan'trethrowInterrupt

java - Java的Thread.sleep什么时候抛出InterruptedException?

Java的Thread.sleep什么时候抛出InterruptedException?忽略它是否安全?我没有做任何多线程。我只想等待几秒钟再重试一些操作。 最佳答案 您通常不应忽略该异常。请看以下论文:Don'tswallowinterruptsSometimesthrowingInterruptedExceptionisnotanoption,suchaswhenataskdefinedbyRunnablecallsaninterruptiblemethod.Inthiscase,youcan'trethrowInterrupt
12