zoukankan      html  css  js  c++  java
  • 线程状态

    java.lang.Thread.State

     1 public class TheadStatusTest {
     2 
     3     public static void main(String[] args) throws InterruptedException {
     4 
     5         Thread s = new Thread(()->{
     6             try {
     7                 System.out.println(Thread.currentThread().getName());
     8                 Thread.sleep(Integer.MAX_VALUE);
     9             } catch (InterruptedException e) {
    10                 //抛出异常后,线程的标示位已经clear成false了
    11                 // 这里返回false
    12                 System.out.println("INTERRUPTED ..." + Thread.currentThread().isInterrupted());
    13 //                System.out.println("INTERRUPTED ..." + Thread.interrupted());
    14                 e.printStackTrace();
    15 
    16                 //重新设置标示位
    17                 Thread.currentThread().interrupt();
    18                 // 这里返回ture
    19                 System.out.println("INTERRUPTED 2 ..." + Thread.currentThread().isInterrupted());
    20             }
    21         }, "Abc-thread-");
    22         s.start();
    23 
    24         //设置线程标示位为true
    25         s.interrupt();
    26         Thread.sleep(100);
    27         System.out.println("===>"+ s.isInterrupted());
    28     }
    29 }

    InterruptedException抛出之后,线程的状态为什么还是false?

  • 相关阅读:
    POJ3186(KB12-O DP)
    POJ1661(KB12-M DP)
    POJ2533(KB12-N LIS)
    POJ1458(KB12-L LCS)
    HDU1160(KB12-J DP)
    HDU1260(KB12-H DP)
    HDU1114(KB12-F DP)
    HDU1024(DP)
    HDU1074(KB12-D 状态压缩dp)
    天梯赛2016-L2
  • 原文地址:https://www.cnblogs.com/yszzu/p/9383134.html
Copyright © 2011-2022 走看看