Java - Design Pattern - Singleton

From My Limbic Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

<source lang="Java">

public class SingletonClass {

   private static SingletonClass SINGLE_INSTANCE = null;
   private SingletonClass() {}
   public static SingletonClass getInstance() {
       if (SINGLE_INSTANCE == null) {
           synchronized (SingletonClass.class) {
               if (SINGLE_INSTANCE == null) {
                   SINGLE_INSTANCE = new SingletonClass();
               }
           }
       }
       return SINGLE_INSTANCE;
   }

} </source>