package com.fh.interview;

/**
 * 中断测试
 *
 * @author
 * @create 2018-05-27 下午3:18
 **/
public class InterruptDemo {

    public static void main(String[] args) {
        Thread sleepThread = new Thread(){
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                }catch (Exception e){

                }
            }
        };

        Thread busyThread = new Thread(){
            @Override
            public void run() {
                while (true);
            }
        };

        sleepThread.start();
        busyThread.start();
        //当对象调用wait,sleep,join的时候,调用中断会清除标志位
        sleepThread.interrupt();
        busyThread.interrupt();
        while (sleepThread.isInterrupted());
        System.out.println("sleep:"+sleepThread.isInterrupted());
        System.out.println("busy:"+busyThread.isInterrupted());
    }
}
View Code

相关文章:

  • 2021-08-18
  • 2021-11-17
  • 2021-12-28
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2021-11-20
  • 2022-12-23
  • 2021-07-25
  • 2021-11-23
相关资源
相似解决方案