package com.company;
//可重入锁
public class ReentrantLock {
public static void main(String[] args) {
Phone phone = new Phone();
new Thread(phone::sms,"A").start();
new Thread(phone::sms,"B").start();
}
}
class Phone{
public synchronized void sms(){
System.out.println(Thread.currentThread().getName()+"sms");
call();
}
public synchronized void call(){
System.out.println(Thread.currentThread().getName()+"call");
}
}
狂神JUC——可重入锁
最新推荐文章于 2022-12-28 11:22:03 发布