이중 잠금 단일 클래스

526 단어 단례
public class Singleton {
	
	private static Singleton instance;
	private static  Object syncRoot = new Object();
	private Singleton() {}
	
	public static Singleton getInstance(){
		
		
		if(instance == null){
			
			synchronized (syncRoot) {
				
				if(instance == null){
					instance = new Singleton();
				}
			}
		}
		return instance;
	}
	

 
라인 안전 하의 단일 종류, 이중 잠금
 

좋은 웹페이지 즐겨찾기