先看三个方法原型: public void interrupt(): public boolean isInterrupted(): public static boolean interrupted(): 一.先说interrupt()方法,看注释 Interrupts this thread. Unless the current thread is interrupting itself, which is always permitted, the checkAccess method
//要点17: 如果前面的方法要调用后面的方法, 后面的方法需要提前声明 function MyFunB(x: Integer): Integer; forward; {使用 forward 指示字提前声明} function MyFunA(x: Integer): Integer; begin Result := MyFunB(x) * ; {要调用后面的方法, 后面的方法需要提前声明} end; function MyFunB(x: Integer): Integer; begin
interrupt 下面是interrupt方法的文档的一部分: * <p> If this thread is blocked in an invocation of the {@link * Object#wait() wait()}, {@link Object#wait(long) wait(long)}, or {@link * Object#wait(long, int) wait(long, int)} methods of the {@link Object} * class,
1. 当线程处于Blocked状态(sleep,wait,join),线程会退出阻塞状态,并抛出一个InterruptedException.park除外,它有响应但是不会抛出异常 2. 当线程处于Running状态,只是线程的interrupt标记被设置为true,线程本身的运行不会受到任何影响. 上面说得其实还不是特别准确,Java 1.8的Thread.interrupt()方法的注释如下,这个应该是最为权威准确的 Unless the current thread is interrup
线程interrupt方法: interrupt方法是用来停止线程的,但是他的使用效果并不像for+break那样,马上就停止循环. 调用interrupt()其实仅仅是在当前线程中打了一个停止标记,并没有真正的停止线程. 在下面的例子中,可以看出在interrupt()方法后的语句仍然被执行了. public class ThreadRunMain { public static void main(String[] args) { testMainInterruptThread(); } p