提交 e1f178b7 编写于 作者: 武汉红喜's avatar 武汉红喜

concurrent test

上级 c51a30fe
package org.hongxi.java.util.concurrent;
/**
* Created on 2019/8/10.
*
* @author shenhongxi
*/
public class InterruptTest {
public static void main(String[] args) {
Thread t = new Thread(() -> {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().isInterrupted()); // false
});
t.start();
t.interrupt(); // Just to set the interrupt flag
System.out.println(t.isInterrupted()); // true
}
}
package org.hongxi.java.util.concurrent;
/**
* Created on 2019/8/10.
*
* @author shenhongxi
*/
public class InterruptTest2 {
public static void main(String[] args) {
Thread t = new Thread(() -> {
System.out.println(Thread.interrupted()); // currentThread().isInterrupted(true);
System.out.println(Thread.interrupted());
});
t.start();
t.interrupt(); // Just to set the interrupt flag
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册