Views 11598 Votes 0 Comment 0
Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

싱글톤 패턴 간단 예제

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) {
    }
}

?

List of Articles
No. Category Subject Author Date Views
101 Develop 리팩토링 계획안 file hooni 2017.05.15 750
100 System/OS [windows] 윈도우즈 콘솔에서 정품인증 하는 방법 hooni 2017.05.24 5331
99 Develop 사이버보안실무 발표자료 (2017.06.08) file hooni 2017.06.05 1210
98 Develop 캘리포니아 운전면허 족보 file hooni 2017.06.12 738
97 Develop [android] 간단한 SQLIite 예제 hooni 2017.06.14 1328
96 Develop [android] SQLiteOpenHelper를 이용한 DBManager hooni 2017.06.14 2070
95 Etc IT감사 기법 시험 file hooni 2017.06.14 1421
94 Develop [coding] Find all anagrams in a string hooni 2017.06.27 1142
93 Develop [coding] 공부해야 하는거 ㅋㅋ secret hooni 2017.06.27 0
92 Develop [android] 안드로이드 앱 문서 샘플 - NCComix file hooni 2017.07.11 2109
91 Etc 캘리포니아 운전면허 문제 file hooni 2017.07.22 980
90 System/OS [mac] Homebrew/rvm/cocoapod setting hooni 2017.07.29 1001
89 Develop [ios] VIN Scanner (VIN barcode) 스캐너 file hooni 2017.09.16 648
88 System/OS [linux] iptables 초간단 세팅 스크립트 hooni 2017.09.26 1241
87 Etc 영어. 불규칙 동사 정리 file hooni 2017.10.04 3509
86 Etc How to completely Uninstall Coda hooni 2017.10.24 2167
Board Pagination Prev 1 ... 66 67 68 69 70 ... 74 Next
/ 74