各位大大好,目前正在k Design Patten,
下面有一段code裡面關於synchronized的部分想請教:
public class Singleton{
private volatile static Singleton uniqueInstance;
private Singleton(){}
public static Singleton getInstance(){
if(uniqeInstance == null){
synchronized(Singleton.class){
^^^^^^^^^^^^^^^^^
if(uniqeInstnace == null)
uniqueInstance = new Singleton();
}
}
}
}
對Synchronized block的觀念比較薄弱,以前大部分都用this,
用來鎖當前物件比較多,想請問這邊的Singleton.class鎖的是? 感謝!!