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

?

  1. [c] 압축 알고리즘 소스 및 정리

  2. [mysql] 쿼리 실행시 ERROR 1366 (HY000) : incorrect string value : for column

  3. [java] 채팅창 처럼.. swing..

  4. [c] OpenGL 시어핀스키 가스킷(p.73 - 첫시간)

  5. [c++] 중복실행 방지(Mutex;뮤텍스 ) 샘플 소스.. ㅋㅋ

  6. [c] OpenGL 마우스 이벤트

  7. [linux] man 명령어 뽀개기..

  8. [c] 캘린더 양음 변환 함수

  9. [js] Text 중 URL 형식을 인식해 단축 URL로 변경

  10. [java] Interface 와 abstract

  11. [php] 초간단 게시판 페이지 분할 알고리즘

  12. [asem] CMOS 패스워드 알아내기.. 소스..

  13. 논문 실험용 고려대 툴바 ㅎㅎ

  14. [css] 화면 스크롤 제어 ㅋㅋ

  15. [asp] 문자열 넘겨받기 (get,post)

  16. [c++] namespace 사용 예

Board Pagination Prev 1 ... 33 34 35 36 37 ... 74 Next
/ 74