04 2022 档案

摘要:使用 condition 交替打印字符串 A、B、C public class PrintTest { private volatile static int num = 1; private static ReentrantLock lock = new ReentrantLock(); priv 阅读全文
posted @ 2022-04-06 00:20 纵码万水千山 阅读(74) 评论(0) 推荐(0) 编辑
摘要:synchronized 与 wait()和 notify() 、notifyAll() 方法相结合可以实现等待/通知模式,ReentantLock 同样也可以实现,需要借助 Condition 实现 public class ConditionTest { private Lock lock = 阅读全文
posted @ 2022-04-04 18:24 纵码万水千山 阅读(48) 评论(0) 推荐(0) 编辑
摘要:1. 懒汉模式,双层检查机制 public class SingleOne { private static volatile Object object=null; /** * 懒汉模式 * 双重判断模式 * @return */ public static Object getInstance( 阅读全文
posted @ 2022-04-04 18:19 纵码万水千山 阅读(33) 评论(0) 推荐(0) 编辑