信号量是拿来消费的,中断一个线程俩次,这个线程会收到俩个信号,同样,它可以消费俩次
public class Interrupt { public static void main(String[] args) throws InterruptedException { Thread t = new Thread(new Runnable() { public void run() { while (true) { if (Thread.interrupted()) { System.out.println("被中断"); } else { System.out.println("没有被中断"); } } } }); t.start(); t.interrupt(); t.interrupt(); System.out.println("main1:" + t.isInterrupted()); System.out.println(Thread.interrupted()); System.out.println("main2:" + t.isInterrupted()); System.out.println("main3:" + t.isInterrupted()); } }