Develop
2013.11.18 17:11
[java] 초간단 싱글톤(Singleton) 패턴 샘플 코드
조회 수 12544 댓글 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] 동영상 플레이어 샘플 (for PIP Player)
-
[php] 한샘 전자발주 시스템..
-
[java] 날짜 계산 (Date, SimpleDateFormat)
-
SVN 명령어 (SVN command)
-
[c++] 현승이가 준 P2P 프로그램 소스 ㅋㅋ
-
JSON, BSON 변환
-
[ios] Background 에서 네트워크 사용
-
Mac OS 에 Jenkins 설치하기 (Homebrew)
-
[c++] 기초강좌 #03(함수의 매개변수 전달)
-
[c] 네트워크 트래릭 모니터링.. 졸업작품..
-
[c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드
-
[ios] 네트워크 인디케이터(NetworkActivityIndicator) 작동