菜菜

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

信号量是拿来消费的,中断一个线程俩次,这个线程会收到俩个信号,同样,它可以消费俩次

public class Interrupt
{

    public static void main(String[] args) throws InterruptedException
    {
        Thread t = new Thread(new Runnable()
        {

            public void run()
            {
                while (true)
                {
                    if (Thread.interrupted())
                    {
                        System.out.println("被中断");
                    }
                    else
                    {
                        System.out.println("没有被中断");
                    }
                }
            }
        });
    
        t.start();
        t.interrupt();
        t.interrupt();
        System.out.println("main1:" + t.isInterrupted());
        System.out.println(Thread.interrupted());
        System.out.println("main2:" + t.isInterrupted());
        System.out.println("main3:" + t.isInterrupted());
    }

}

 

posted on 2016-12-29 00:42  好吧,就是菜菜  阅读(155)  评论(0编辑  收藏  举报