Develop
2013.11.18 17:11
[java] 초간단 싱글톤(Singleton) 패턴 샘플 코드
조회 수 11605 댓글 0
첨부 '1' |
---|
싱글톤 패턴 간단 예제
import java.util.HashMap; class Singleton { private static HashMap map = new HashMap(); //private static Logger logger = Logger.getRootLogger(); protected Singleton() { // Exists only to thwart instantiation } public static synchronized Singleton getInstance(String classname) { Singleton singleton = (Singleton)map.get(classname); if(singleton != null) { System.out.println("got singleton from map: " + singleton); return singleton; } try { singleton = (Singleton)Class.forName(classname).newInstance(); } catch(ClassNotFoundException cnf) { System.out.println("Couldn't find class " + classname); } catch(InstantiationException ie) { System.out.println( "Couldn't instantiate an object of type " + classname); } catch(IllegalAccessException ia) { System.out.println("Couldn't access class " + classname); } map.put(classname, singleton); System.out.println("created singleton: " + singleton); return singleton; } } class SingletonTest { public static void main(String[] args) { } }
-
'2014 모바일 개발 트렌드' 발표자료입니다.
-
[ios] iOS 8 개발자가 우선 알아야 할 3가지
-
[js] jQuery 셀 병합
-
IoT가 만드는 미래와 플랫폼 경쟁력
-
SVN(Subversion) 설치와 설정 (sasl 인증 적용 포함)
-
[linux] yum 업데이트 시 커널 제외하기
-
[ios] Xcode cannot run using the selected device
-
[ios] Objective-C 에서 자주 사용하는 수학 함수와 유용한 Define
-
[ios] 카테고리 확장 메소드를 찾지 못하는 경우
-
[ios] @property의 속성 (strong, weak, copy) 사용 경우
-
OCB5 Injection 앗싸뵹! ㅋㅋ
-
[ios] TextField 특정 문자만 사용하도록 하기