日期:2014-05-20  浏览次数:20675 次

线程杂么中断不了呢。。。
我启动一个线程,然后向中断它,但是中断不了,一直运行。求解。

Java code

public class Test2 {

    /**
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new T());
        t.start();
        Thread.sleep(3000);
        t.interrupt();
    }

}

class T extends Thread {

    @Override
    public void run() {

        while (true) {
            if (this.isInterrupted()) {
                System.out.println("被打断了");
                break;
            }
            System.out.println("running");
        }
    }
}



------解决方案--------------------
恭喜楼主解决问题