package com.lovecoding.day14.thread05;

public class Product {

    //锁1
    private Object obj1 = new Object();

    //锁2
    private Object obj2 = new Object();

    //发货
    public void put(){
        //死锁
        synchronized (obj1){
            System.out.println("先打钱");
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (obj2){
                System.out.println("发货");
            }
        }
    }

    //给钱
    public void money(){
        synchronized (obj2){
            System.out.println("先发货");
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (obj1){
                System.out.println("打钱");
            }
        }
    }


}
