zoukankan      html  css  js  c++  java
  • 单例模式

    http://baike.baidu.com/view/1859857.htm
    单例模式一般有三种形式

    //1.饿汉式

    public class Singleton1 {

     

             private static Singleton1 instance = new Singleton1();

     

             private Singleton1() {

             }

     

             static Singleton1 getInstance() {

                       return instance;

             }

     

    }


    *************************************************************************************************************************************************************************

    //2.懒汉式

    public class Singleton2 {

     

             private static Singleton2 instance = null;

     

             private Singleton2() {

             }

     

             static Singleton2 getInstance() {

                       if (instance == null)

                                instance = new Singleton2();

                       return instance;

             }

    }

    *************************************************************************************************************************************************************************


    //
    双重锁的形式。

    public class Singleton3 {

             private static Singleton3 instance = null;

             private Singleton3(){

                       //do something

             }

             public static Singleton3 getInstance(){

                       if(instance==null){

                                synchronized(Singleton3.class){

                                         if(null == instance){ 

                                                   instance = new Singleton3();

                                         }

                                }

                       }

                       return instance;

             }

    }

     

  • 相关阅读:
    3-2 表的增删改查
    3-1 存储引擎的介绍
    2-1 库的增删改查
    1-4 初识sql语句
    1-3 mysql的安装和基本管理
    1-2 数据库概述
    1-1 数据库管理软件的由来
    4-6 IO模型对比
    《测试软件工程师》11,13 测试用例格式
    《软件测试工程师》10 测试环境搭建
  • 原文地址:https://www.cnblogs.com/gxpblogs/p/3068001.html
Copyright © 2011-2022 走看看