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

?

  1. [C#] MD5, SHA1 해시 & 인코딩

    Date2013.04.23 CategoryDevelop Byhooni Views77855
    Read More
  2. 디피헬만(Diffie-Hellman) 초간단 개념..

    Date2013.04.23 CategoryAlgorithm Byhooni Views81019
    Read More
  3. [c#] 웹문서 소스(html) 긁어오기

    Date2013.04.23 CategoryDevelop Byhooni Views24506
    Read More
  4. [sql] insert into select 사용하기

    Date2013.04.23 CategorySystem/OS Byhooni Views27554
    Read More
  5. [android] 만화 어플 소스코드

    Date2013.04.23 CategoryDevelop Byhooni Views92836
    Read More
  6. [ios] 미스터피자(Mr.pizza) 어플

    Date2013.04.23 CategoryDevelop Byhooni Views42631
    Read More
  7. [iphone] 아이폰 어플 모음 ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views13707
    Read More
  8. [android] 안드로이드 어플 모음 ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views16340
    Read More
  9. [lego] 세그웨이 이것만 볼것.. ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views33536
    Read More
  10. [json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드)

    Date2013.04.23 CategoryDevelop Byhooni Views71971
    Read More
  11. [c#] Hashtable <-> Json (dll 포함)

    Date2013.04.23 CategoryDevelop Byhooni Views80652
    Read More
  12. [c#] Json 라이브러리 (System.Net.Json.dll)

    Date2013.04.23 CategoryDevelop Byhooni Views58536
    Read More
  13. [c#] 간단한 IPC 통신 예제

    Date2013.04.23 CategoryDevelop Byhooni Views63729
    Read More
  14. [c#] 간단한 소켓통신 예제..

    Date2013.04.23 CategoryDevelop Byhooni Views26692
    Read More
  15. [c#] 비동기 통신 샘플 코드 ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views23635
    Read More
  16. [c#]업글 뉴 툴바 개인적으로 만든거.. (new) ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views7651
    Read More
Board Pagination Prev 1 ... 29 30 31 32 33 ... 74 Next
/ 74