public static void main(String... args){
Thread.currentThread().interrupt();
logger.warn("{}", Thread.currentThread().isInterrupted());//true
logger.warn("{}", Thread.currentThread().isInterrupted());//false
}
结果显示:isInterrupted()
的第一次调用返回true
,isInterrupted()
的第二次调用返回false,我读到Thread.isInterrupted()
的DOC时说:{{ 1}}
因此,为什么Tests whether this thread has been interrupted. The <i>interrupted status</i> of the thread is unaffected by this method.
的第二次调用和后续调用都返回false,无论根据DOC调用了多少次isInterrupted()
,它都应该始终返回true。