package com.concurrent.interrupt;

/**
 * <p/>
 * User : krisibm@163.com
 * Date: 2015/9/8
 * Time: 13:17
 */
public class SleepInterrupt implements Runnable {
    @Override
    public void run() {

        try {
            System.out.println("run() sleep 10 seconds");
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            System.out.println("run() - interrupted while sleeping");
            //处理完中断异常后，返回到run（）方法人口，
            //如果没有return，线程不会实际被中断，它会继续打印下面的信息
            return;
        }

        System.out.println("run() - leaving normally");
    }


    public static void main(String[] args) {

        SleepInterrupt sleepInterrupt = new SleepInterrupt();
        Thread thread = new Thread(sleepInterrupt);
        thread.start();

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main() - interrupting other thread");

        thread.interrupt();

        System.out.println("main() - end");
    }

}

@@ -813,17 +813,17 @@
 d.sleep(
-2
+4
 000);%0A  

update time