首页 > 其他 > 详细

中断方法测试

时间:2018-05-27 16:13:05      阅读:201      评论:0      收藏:0      [点我收藏+]
技术分享图片
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

 

中断方法测试

原文:https://www.cnblogs.com/nihaofenghao/p/9096221.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!