编程语言
首页 > 编程语言> > java锁的应用

java锁的应用

作者:互联网

1、重量级锁sychronized

    public synchronized String testLock01() {
        // todo 业务逻辑
        return "test01";
    }

    public String testLock02() {
        synchronized (this) {
            System.out.println("true = " + true);
        }
        return "test02";
    }

 

2、reentrantLock

    final ReentrantLock reentrantLock = new ReentrantLock();

    public String test02() {
        reentrantLock.lock();
        System.out.println("销住的代码");
        reentrantLock.unlock();
        return "test02";
    }

 

标签:return,String,synchronized,reentrantLock,应用,test02,java,public
来源: https://www.cnblogs.com/txt1024/p/15877196.html