mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-20 22:17:09 +08:00
Update JavaConcurrencyAdvancedCommonInterviewQuestions.md
单例模式实例修改,在单例方法上声明synchronized关键字是不必要的且会造成性能上的开销
This commit is contained in:
parent
90f1744da0
commit
e88e2892ea
@ -73,7 +73,7 @@ public class Singleton {
|
|||||||
private Singleton() {
|
private Singleton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static Singleton getUniqueInstance() {
|
public static Singleton getUniqueInstance() {
|
||||||
//先判断对象是否已经实例过,没有实例化过才进入加锁代码
|
//先判断对象是否已经实例过,没有实例化过才进入加锁代码
|
||||||
if (uniqueInstance == null) {
|
if (uniqueInstance == null) {
|
||||||
//类对象加锁
|
//类对象加锁
|
||||||
|
Loading…
x
Reference in New Issue
Block a user