InterruptCheck.java
上传用户:songled
上传日期:2022-07-14
资源大小:94k
文件大小:1k
源码类别:

进程与线程

开发平台:

Java

  1. public class InterruptCheck extends Object {
  2. public static void main(String[] args) {
  3. Thread t = Thread.currentThread();
  4. System.out.println("Point A: t.isInterrupted()=" + t.isInterrupted());
  5. t.interrupt();
  6. System.out.println("Point B: t.isInterrupted()=" + t.isInterrupted());
  7. System.out.println("Point C: t.isInterrupted()=" + t.isInterrupted());
  8. try {
  9. Thread.sleep(2000);
  10. System.out.println("was NOT interrupted");
  11. } catch ( InterruptedException x ) {
  12. System.out.println("was interrupted");
  13. }
  14. System.out.println("Point D: t.isInterrupted()=" + t.isInterrupted());
  15. }
  16. }