ITeye博客

单例模式

wangdf_jee · 2012-08-28 16:19 · Java · 编程语言 · Markdown


package com.wdf;

public class Singleton {

	private volatile static Singleton singleton = null;

	private Singleton() {

	}

	public static Singleton getInstance() {

		if (singleton == null) {
			synchronized (Singleton.class) {
				//double checked locking
				if (singleton == null) {
					singleton = new Singleton();
				}
			}

		}

		return singleton;

	}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。