线程安全的单例模式

个人认为写的比较好的JAVA单例模式
public class Test {
	private Test() {

	}

	public static Test singleTon = getInstance();

	public static Test getInstance() {
		synchronized (Test.class) {
			if (singleTon == null) {
				singleTon = new Test();
			}
		}
		return singleTon;
	}
}

你可能感兴趣的:(java)