Develop
2013.11.18 17:11
[java] 초간단 싱글톤(Singleton) 패턴 샘플 코드
조회 수 11632 댓글 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) { } }
-
알고리즘 성능분석
-
[ios] iOS에서 디바이스 종류 알아오기
-
[ios] 아이폰 GPS 사용하기
-
[ios] 언어, 지역, 국가 설정 가져오기
-
[ios] URL 파라미터 파싱~
-
[ios] 앱 딜리게이트 얻어오기. (AppDelegate)
-
[ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle)
-
[ios] 애플 앱스토어 IDFA 리뷰 정책 변경 안내
-
[ios] NSString URL Encode/Decode (인코딩/디코딩)
-
[ios] 커스텀 폰트 사용하기 (Custom Fonts)
-
[ios] iOS 의 인앱구매 소개
-
[js] Array.splice() 설명