interrupt不是结束线程,是改变线程的状态。
比如原来一个线程在wait,那么interrupt可以告诉他:“好了,该干啥干啥去吧,别整天吃饱了没事干就在那里wait啦”

解决方案 »

  1.   

    public void interrupt()
    Interrupts this thread. 
    First the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown. If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException. If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException. If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked. If none of the previous conditions hold then this thread's interrupt status will be set.
      

  2.   

    那就是说调用该方法后,并不影响线程的运行情况,只是设置一下status吗?
      

  3.   

    嗯,我据的是。wait的地方会被抛出一个Exception。
      

  4.   

    interrupt在我影响中是不结束线程对对象级别的占有,而stop就相当于强迫让线程结束,让出级别占有If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked. 调用interrupt会使run立刻返回,结束interrupt后相当于调用了wakeup方法