记一次idea debug和实际值不一致的过程

在阅读CountDownLatch.await()方法时看到如下代码:

    public void await() throws InterruptedException {
        sync.acquireSharedInterruptibly(1);
    }

    public final void acquireSharedInterruptibly(int arg)
            throws InterruptedException {
        if (Thread.interrupted())     //问题点
            throw new InterruptedException();
        if (tryAcquireShared(arg) < 0)
            doAcquireSharedInterruptibly(arg);
    }

当前线程被打断时,调用await()方法将会抛出InterruptedException异常。

测试代码:

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        Thread.currentThread().interrupt();
        countDownLatch.await();
    }

运行程序抛出InterruptedException异常,是符合预期的。但是当BUBUG查看Thread.interrupted()执行结果时,却发现返回结果为false,但是实际值应该是true。

​ 在Eclipse测试时,情况和idea是一样的,这就很费解,目前没有明白是什么原因...,先记录下。

图1
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容