我们知道DCL双重锁的写法是:
if (null == singletonLazy) {
synchronized (SingletonLazy5.class) {
if(null == singletonLazy) {
singletonLazy = new SingletonLazy5();
}
}
}
那么为什么有两层判断呢?写成下面这样有哪些缺点呢?
synchronized (SingletonLazy5.class) {
if(null == singletonLazy) {
singletonLazy = new SingletonLazy5();
}
}
梦里花落0921
宝慕林4294392
随时随地看视频慕课网APP
相关分类