单例工厂适配器装饰器
Posted siyyawu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单例工厂适配器装饰器相关的知识,希望对你有一定的参考价值。
单例
单例分为懒汉式和饿汉式
1 public class Singleton { 2 3 4 //饿汉加载 5 //应用时才加载,节省内存 6 private static Singleton instance; 7 private Singleton() { 8 } 9 public static Singleton getInstance(){ 10 if (instance == null) { 11 synchronized (Singleton.class) { 12 if (instance == null) { 13 instance = new Singleton(); 14 } 15 } 16 } 17 return instance; 18 } 19 20 21 //饿汉加载 22 //浪费内存 23 // private static Singleton singleton=new Singleton(); 24 // public static Singleton getInstance(){ 25 // return singleton; 26 // } 27 28 public void run(){ 29 System.out.println("hellowolrd"); 30 } 31 }
工厂模式:
以上是关于单例工厂适配器装饰器的主要内容,如果未能解决你的问题,请参考以下文章