Java Singleton 문제 정답(DCL)
public class Singleton { //쓰레드에서 변수의 변화를 바로 감지하게 하기 위함 private volatile static Singleton instance; private Singleton() { } public static Singleton getInstance() { // 생성할때만 초기화 한다. if (instance == null) { // 클래스 단위로 락을 건다. static 이므로 synchronized (Singleton.class) { if (instance == null) { instance = new Singleton(); } } } return instance; } }
프로그래밍
2017. 3. 27. 23:54
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday