testinterrupt.java

来自「java2 primer plus一书源程序」· Java 代码 · 共 70 行

JAVA
70
字号
/* * TestInterrupt.java * * Created on September 25, 2002, 12:08 PM */package ch18;/** * * @author  Stephen Potts */public class TestInterrupt extends Thread{        /** Creates a new instance of TestInterrupt */    public TestInterrupt()    {    }        public void run()    {        try        {                        for ( int i=0; i<5; i++)            {                System.out.println("running the first loop " + i);            }            Thread.sleep(10000);                        for ( int i=6; i<10; i++)            {                System.out.println("running the second loop" + i);            }                    }catch (InterruptedException ie)        {            System.out.println("Sleep interrupted in run()");            for ( int i=11; i<15; i++)            {                System.out.println("running the third loop" + i);            }                    }            }        public static void main(String[] args)    {        TestInterrupt ti = new TestInterrupt();        Thread t = new Thread(ti);        t.start();                //Delay for a few seconds to let the other thread get going        try        {            Thread.sleep(2500);        }catch (InterruptedException ie)        {            System.out.println("Sleep interrupted in main()");        }                System.out.println("About to wake up the other thread");        t.interrupt();        System.out.println("Exiting from Main");            }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?