---
title: "多线程-单例设计模式-懒汉式"
author: "wststar"
date: "2012-05-22T08:57:55Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-05-21T17:57:25Z"
id: 1536520
url: "https://wststar.iteye.com/blog/1536520"
---

/\**

多线程-单例设计模式-懒汉式

单例设计模式-饿汉式

class Single

{

private static final Single s = new Single();

private Single(){}

public static getInstance(){

return s;

}

} 

单例设计模式-懒汉式 延迟加载 解决多线程安全问题 

用同步函数效率慢 使用双重判断 同步代码块判断 效率快

\*/

class Single

{

private static Single s = null;

private Single(){}

public static getInstance(){

if(null == s){

synchronized(Single.class){

if(null == s){

s = new Single();

}

return s;

}

}

}

}

class SingleDemo 

{

public static void main(String\[] args) 

{

System.out.println("Hello World!");

}

}