Develop
2013.11.18 17:11
[java] 초간단 싱글톤(Singleton) 패턴 샘플 코드
조회 수 12552 댓글 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) { } }
-
[android] 가속도 센서를 이용한 흔듦(Shake) 감지
-
[web] 더 빠른 웹을 위한 프로토콜, 'HTTP/2'
-
GPL, AGPL, MPL,.. 한눈에 보는 오픈소스SW 라이선스
-
[js] 좋은 강연자료 & UI 자료
-
'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