A better singleton without synchronized.

http://stackoverflow.com/questions/16106260/thread-safe-singleton-class

public class Something {
    private Something() {}

    private static class LazyHolder {
        private static final Something INSTANCE = new Something();
    }

    public static Something getInstance() {
        return LazyHolder.INSTANCE;
    }
}

 

posted @ 2016-09-20 14:47  chuiyuan  阅读(117)  评论(0编辑  收藏  举报