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) { } }
-
[c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기)
-
[unix] 쉘 스크립트 예제 모음
-
[ios] UIWebView에서 NSURLRequest에 Cookie 실어 보내기
-
[unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값)
-
[css] z-index에 설정할 수 있는 최대값?
-
[ios] Objective-C에서 SQLite 사용하기..
-
[ios] iOS In App Purchase #1 (코드 구현 전 웹 설정 작업)
-
[c] 메시지큐(Message Queue) 설명.. (joinc)
-
[c] vc++ 에서 clrscr(), gotoxy() 함수 사용하기..
-
[c] 64bit 머신에서 inet_ntoa() 사용시 Segment fault 대처 방법법
-
[C] C언어의 조건 연산자(Conditional Operator)
-
[c] 민수형 libipq 샘플 소스 ㅋㅋ