HSDIS查看Java代码的汇编指令
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssemble
使用 LockSupport.park()and unpark()
public static void main(String[] args) { char[] aI = "1234567".toCharArray(); char[] aC = "ABCDEFG".toCharArray(); Lock lock = new ReentrantLock(); Condition conditionT1 = lock.newCondition(); Condition conditionT2 = lock.newCondition(); new Thread(() -> { try { lock.lock(); for (char c : aI) { System.out.print(c); conditionT2.signal(); conditionT1.await(); } conditionT2.signal(); } catch (Exception e) { e.printStackTrace(); } finally { lock.unlock(); } }, "t1").start(); }