Contents

조회 수 11605 댓글 0
Atachment
첨부 '1'
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

싱글톤 패턴 간단 예제

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++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기)

    Date2013.04.23 CategoryDevelop Byhooni Views14998
    Read More
  2. [unix] 쉘 스크립트 예제 모음

    Date2003.04.23 CategoryDevelop Byhooni Views14950
    Read More
  3. [ios] UIWebView에서 NSURLRequest에 Cookie 실어 보내기

    Date2014.01.16 CategoryDevelop Byhooni Views14861
    Read More
  4. [unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값)

    Date2013.04.23 CategoryDevelop Byhooni Views14829
    Read More
  5. [css] z-index에 설정할 수 있는 최대값?

    Date2013.12.20 CategoryDevelop Byhooni Views14720
    Read More
  6. [ios] Objective-C에서 SQLite 사용하기..

    Date2013.04.23 CategoryDevelop Byhooni Views14562
    Read More
  7. [ios] iOS In App Purchase #1 (코드 구현 전 웹 설정 작업)

    Date2013.11.20 CategoryDevelop Byhooni Views14520
    Read More
  8. [c] 메시지큐(Message Queue) 설명.. (joinc)

    Date2013.04.23 CategoryDevelop Byhooni Views14280
    Read More
  9. [c] vc++ 에서 clrscr(), gotoxy() 함수 사용하기..

    Date2013.04.23 CategoryDevelop Byhooni Views14254
    Read More
  10. [c] 64bit 머신에서 inet_ntoa() 사용시 Segment fault 대처 방법법

    Date2014.02.08 CategoryDevelop Byhooni Views14237
    Read More
  11. [C] C언어의 조건 연산자(Conditional Operator)

    Date2003.04.23 CategoryDevelop Byhooni Views14230
    Read More
  12. [c] 민수형 libipq 샘플 소스 ㅋㅋ

    Date2003.04.23 CategoryDevelop Byhooni Views14113
    Read More
Board Pagination Prev 1 ... 9 10 11 12 13 14 15 16 17 18 ... 71 Next
/ 71