Develop
2013.11.18 17:11
[java] 초간단 싱글톤(Singleton) 패턴 샘플 코드
조회 수 11591 댓글 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) { } }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
813 | System/OS | [linux] 기본 명령어 (내공쌓기) | hooni | 2003.04.23 | 14333 |
812 | System/OS | [linux] 계정관리하기(내공쌓기) | hooni | 2003.04.23 | 13157 |
811 | System/OS | [linux] 간단한 vi편집기 사용 명령 | hooni | 2003.04.23 | 13456 |
810 | System/OS | [linux] 간단한 NAT 설정 script | hooni | 2003.04.23 | 12593 |
809 | System/OS | [linux] 간단한 find 명령어 설명(업데이트 해야 함) | hooni | 2013.04.23 | 9111 |
808 | System/OS | [linux] yum 업데이트 시 커널 제외하기 | hooni | 2014.09.11 | 1256 |
807 | System/OS | [linux] X환경 GNOME에서 KDE로 바꾸는 법.. | hooni | 2013.04.23 | 12365 |
806 | System/OS | [linux] Xwindow/Xmanager 사용 | hooni | 2003.04.23 | 13330 |
805 | System/OS | [linux] wget 명령 사용 예제 | hooni | 2020.05.26 | 1430 |
804 | System/OS | [linux] vi 편집기 간단한 명령과 환경설정 | hooni | 2003.04.23 | 11359 |
803 | System/OS | [linux] The Ultimate Wget Download Guide With 15 Awesome Examples | hooni | 2020.05.26 | 795 |
802 | Develop | [linux] tar 명령어 뽀개기.. ㅋㅋ | hooni | 2003.04.23 | 7669 |