---
title: "单例模式"
author: "wangdf_jee"
date: "2012-08-28T16:19:57Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-08-28T16:19:57Z"
id: 1665414
url: "https://wangdf-jee.iteye.com/blog/1665414"
---

```java

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;

	}
}

```