Contents

조회 수 12548 댓글 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. [ios] Background 에서 네트워크 사용

    Date2013.07.22 CategoryDevelop Byhooni Views13158
    Read More
  2. [linux] X환경 GNOME에서 KDE로 바꾸는 법..

    Date2013.04.23 CategorySystem/OS Byhooni Views13140
    Read More
  3. JSON, BSON 변환

    Date2013.04.23 CategoryDevelop Byhooni Views13139
    Read More
  4. [linux] /etc/fstab 설정 방법.. ㅋㅋ

    Date2013.04.23 CategorySystem/OS Byhooni Views13137
    Read More
  5. SVN 명령어 (SVN command)

    Date2014.02.28 CategoryDevelop Byhooni Views13044
    Read More
  6. [c++] 현승이가 준 P2P 프로그램 소스 ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views13044
    Read More
  7. [java] 날짜 계산 (Date, SimpleDateFormat)

    Date2013.04.23 CategoryDevelop Byhooni Views13018
    Read More
  8. [php] 한샘 전자발주 시스템..

    Date2013.04.23 CategoryDevelop Byhooni Views12987
    Read More
  9. [ios] 동영상 플레이어 샘플 (for PIP Player)

    Date2017.03.15 CategoryDevelop Byhooni Views12921
    Read More
  10. [unix] 유닉스 명령에 메타문자 사용

    Date2014.02.19 CategoryDevelop Byhooni Views12865
    Read More
  11. [swift] NotificationCenter 간단 예제

    Date2021.01.27 CategoryDevelop Byhooni Views12843
    Read More
  12. [php] whois정보 조회 프로그램

    Date2003.04.23 CategoryDevelop Byhooni Views12839
    Read More
Board Pagination Prev 1 ... 30 31 32 33 34 35 36 37 38 39 ... 99 Next
/ 99