Labels

algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)

Singleton Design Pattern

Singleton.jpeg
package singleton;

public class Singleton {
    private static Singleton aSingleton;

    private Singleton() {
    }

    static Singleton getInstance() {
        synchronized (Singleton.class) {
            if (Singleton.aSingleton == null) {
                  Singleton.aSingleton = new Singleton();
            }
        }
        return Singleton.aSingleton;
    }
}


  • only one instance of a class across threads
  • global point of access 








No comments:

Post a Comment

Search 24 Bytes