[LinkedIn] singleton, thread safe

From here

//thread safe singleton. static makes it guarantee that it only gets created at the first time
public class Singleton {
   public final static Singleton INSTANCE = new Singleton();
   private Singleton() {
         // Exists only to defeat instantiation.
      }
}
//how to use it. 
Singleton singleton = Singleton.INSTANCE;
singleton.dothis();
singleton.dothat();
posted on 2015-03-31 00:34  Seth_L  阅读(92)  评论(0编辑  收藏  举报