1. 程式人生 > >java實現執行緒安全的單利模式

java實現執行緒安全的單利模式

public class Object{
	private static Object o = new Object();
	
	private Object(){
	}
	
	private static synchronized void syncInit(){
		if(o == null){
			o = new Object();
		}
	}
	
	public static Object getInstance(){
		if(0 == null){
			syncInit();
		}
		return o;
	}
}