Views 11593 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
693 Develop [pdf] C++ 국제 표준 문서 file hooni 2013.04.23 7281
692 Develop [pdf] C 국제 표준 문서 file hooni 2013.04.23 6743
691 Develop [doc] C언어 문법 설명서 file hooni 2013.04.23 6437
690 Develop [doc] C++언어 문법 설명서 file hooni 2013.04.23 6170
689 Develop [chm] 비주얼 C++ 팁 모음 문서 file hooni 2013.04.23 7500
688 Develop [pdf] 윈도우즈 95 시스템 프로그래밍(Windows 95 system programming) file hooni 2013.04.23 6842
687 Develop [chm] 윈도우즈에서 디버깅 기법(Debugging Applications) file hooni 2013.04.23 7527
686 Develop [chm] C++ 문법 가이드 file hooni 2013.04.23 7942
685 Develop [pdf] 포인터 문법 정리 (C pointer) file hooni 2013.04.23 7102
684 Develop [chm] Programming Applications for Microsoft Windows file hooni 2013.04.23 7267
683 Develop [c] Unix Domain Socket 을 이용한 IPC hooni 2013.04.23 8011
682 Develop [c++] 쓰레드(Thread) 객체의 사용 hooni 2013.04.23 8574
681 System/OS [linux] 프로세스의 stat 상태에 대한 설명 hooni 2013.04.23 10756
680 Develop [php] 빔 프로젝터 예약 프로그램.. ㅋㅋ file hooni 2013.04.23 6918
679 Develop [php] 논문 관리 프로그램.. ㅋㅋ file hooni 2013.04.23 7255
678 Develop [c++] 프리렉(freelec) 예제 자료.. ㅋㄷ file hooni 2013.04.23 6833
Board Pagination Prev 1 ... 29 30 31 32 33 ... 74 Next
/ 74