package com.elab.example.springbootdemo.demo;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * 等待
 *
 * @author ： liukx
 * @time ： 2019/8/14 - 14:47
 */
public class ConditionWait implements Runnable {

    private Lock lock;
    private Condition condition;

    public ConditionWait(Lock lock, Condition condition) {
        this.lock = lock;
        this.condition = condition;
    }

    @Override
    public void run() {
        try {
            this.lock.lock();
            try {
                System.out.println("BEGIN - ConditionWait");
                condition.await();
                System.out.println("END - ConditionWait");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } finally {
            this.lock.unlock();
        }
    }
}
