Condition是Lock的附属物,Condition定义了等待/通知两种类型的方法,当前线程调用这些方法时,需要提前获取到Condition对象关联的锁。
    一个锁可以搞多个Condition

    1. public interface Condition {
    2. /**
    3. * 让当前线程进入等待状态直到被通知或者被中断,当前线程重新进入运行状态且从await方法返回的情况如下
    4. * 1. 其他线程调用了该Condition的signal 或signalAll
    5. * 2. 其他线程调用interrupt中断了当前线程
    6. * @throws InterruptedException
    7. */
    8. void await() throws InterruptedException;
    9. /**
    10. * 等价上面那个
    11. * @param time
    12. * @param unit
    13. * @return
    14. * @throws InterruptedException
    15. */
    16. boolean await(long time, TimeUnit unit) throws InterruptedException;
    17. /**
    18. * 指定到某个时间还没被通知且没被中断直接返回,提前被通知了返回true,否则false
    19. * @param deadline
    20. * @return
    21. * @throws InterruptedException
    22. */
    23. boolean awaitUntil(Date deadline) throws InterruptedException;
    24. /**
    25. * 唤醒等待在Condition上的一个线程
    26. */
    27. void signal();
    28. /**
    29. * 唤醒所有等待在Condition上的线程
    30. */
    31. void signalAll();
    32. }