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) { } }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
817 | System/OS | [linux] 한글 URL 인식할 수 있게 아파치(Apache) 설정 (mod_url.c 설치) | hooni | 2013.04.23 | 13966 |
816 | System/OS | [linux] ipfwadm를 이용한 패킷필터링(구버전) | hooni | 2003.04.23 | 13950 |
815 | System/OS | [linux] ProFTPD 타임아웃 설정 | hooni | 2003.04.23 | 13950 |
814 | Develop |
[c] 다중연결 서버 만들기 #1 - fork() 사용
![]() |
hooni | 2013.04.23 | 13943 |
813 | System/OS | [linux] 아파치설치/설정 - SSI(Server Side Include) | hooni | 2003.04.23 | 13940 |
812 | Etc | 선과 악에 대한 영어논술문항(지킬앤하이드 독서 후 이어지는 심화 수행평가) | hooni | 2013.12.04 | 13904 |
811 | Develop |
[c++] 자료구조(링크리스트,스택,큐)와 후위 표기 계산기 샘플 ㅋㅋ
4 ![]() |
hooni | 2013.04.23 | 13891 |
810 | Develop |
[php] 심플한 게시판 ㅋㅋ
1 ![]() |
hooni | 2013.04.23 | 13859 |
809 | System/OS | [linux] 콘솔 기본언어 설정 방법 | hooni | 2013.04.23 | 13849 |
808 | System/OS | [linux] 아파치 설치/설정(proxy) | hooni | 2003.04.23 | 13849 |
807 | Develop |
[js] AngularJS를 소개합니다.
![]() |
hooni | 2014.01.06 | 13845 |
806 | System/OS | [linux] Proftpd 설치 가이드 | hooni | 2003.04.23 | 13845 |