public class BlockedWaitingTimeWaiting implements Runnable {
public static void main(String[] args) throws InterruptedException {
BlockedWaitingTimeWaiting runnable = new BlockedWaitingTimeWaiting();
Thread t1 = new Thread(runnable);
t1.start();
Thread t2 = new Thread(runnable);
t2.start();
Thread.sleep(5);
System.out.println(t1.getState()); //TIMED_WAITING : t1正在 Thread.sleep(1000)
System.out.println(t2.getState()); //t2正在 syn() 阻塞,拿不到t1正持有的锁
Thread.sleep(1300);
System.out.println(t1.getState()); //WAITING
System.out.println(t2.getState()); //这里输出的是TIMED_WAITING???
}
@Override
public void run() {
syn();
}
private synchronized void syn() {
try {
Thread.sleep(1000);
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}