Develop
2013.11.18 17:11
[java] 초간단 싱글톤(Singleton) 패턴 샘플 코드
Views 12544 Comment 0
Attachment '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) { } }
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
1177 | Develop | [ios] 아이폰용 앱 오픈 소스들 | hooni | 2013.04.23 | 488152 |
1176 | Develop | [ios] 언어, 지역, 국가 설정 가져오기 | hooni | 2014.05.12 | 290676 |
1175 | Develop | 자주 쓰는 Docker 명령어 alias | hooni | 2020.01.10 | 289336 |
1174 | Etc |
베지어 곡선 (Bezier curve)
![]() |
hooni | 2013.08.18 | 238770 |
1173 | Develop |
[ios] Start developing your navigation app for CarPlay without enrollment
![]() |
hooni | 2020.02.22 | 132646 |
1172 | Etc | [link] 유용한 사이트 링크. | hooni | 2013.08.19 | 129481 |
1171 | Develop |
[android] 만화 어플 소스코드
![]() |
hooni | 2013.04.23 | 96716 |
1170 | Algorithm | 디피헬만(Diffie-Hellman) 초간단 개념.. | hooni | 2013.04.23 | 85678 |
1169 | Develop |
[c#] Hashtable <-> Json (dll 포함)
![]() |
hooni | 2013.04.23 | 84617 |
1168 | Develop |
레고 마인드스톰 NXT 수도쿠, 큐브 소스코드..
20 ![]() |
hooni | 2013.04.23 | 83093 |
1167 | Develop |
[android] 점심 해결 앱 소스 코드 ㅋㅋ
![]() |
hooni | 2013.04.23 | 81363 |
1166 | Develop | [C#] MD5, SHA1 해시 & 인코딩 | hooni | 2013.04.23 | 80939 |