package com.elab.example.springbootdemo.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
 * 是否死锁?
 *
 * @author ： liukx
 * @time ： 2019/8/13 - 14:57
 */
public class App {

    private Logger logger = LoggerFactory.getLogger(App.class);

    public synchronized void demo() {
        logger.info(" demo ");
        demo2();
    }

    public void demo2() {
        synchronized (this) {
            logger.info("demo2");
        }
    }

    public static void main(String[] args) throws InterruptedException {
//        App app = new App();
//        for (int i = 0; i < 5; i++) {
//            Thread thread = new Thread(() -> {
//                app.demo();
//            });
//            thread.start();
//        }

        Lock lock = new ReentrantLock();
        Condition condition = lock.newCondition();
        new Thread(new ConditionSignal(lock, condition)).start();
        Thread.sleep(2000);

        new Thread(new ConditionWait(lock, condition)).start();


    }

}
