<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>欢迎来到huwencheng的博客</title><link>https://lifeloinmg.github.io/huwencheng.github.io</link><description>公开学习成长记录，持续沉淀所学知识点、问题解法与实践经验，打造可追溯的个人知识库。</description><copyright>欢迎来到huwencheng的博客</copyright><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><image><url>https://avatars.githubusercontent.com/u/132213325?s=400&amp;u=4eee6bfadc570c937aa271c237ffb8090717ffdd&amp;v=4</url><title>avatar</title><link>https://lifeloinmg.github.io/huwencheng.github.io</link></image><lastBuildDate>Sun, 29 Mar 2026 14:03:30 +0000</lastBuildDate><managingEditor>欢迎来到huwencheng的博客</managingEditor><ttl>60</ttl><webMaster>欢迎来到huwencheng的博客</webMaster><item><title>测试</title><link>https://lifeloinmg.github.io/huwencheng.github.io/post/ce-shi.html</link><description>测试多级目录信息
测试编辑信息
#1 测试信息。</description><guid isPermaLink="true">https://lifeloinmg.github.io/huwencheng.github.io/post/ce-shi.html</guid><pubDate>Mon, 23 Mar 2026 11:13:07 +0000</pubDate></item><item><title>测试多级目录信息</title><link>https://lifeloinmg.github.io/huwencheng.github.io/post/ce-shi-duo-ji-mu-lu-xin-xi.html</link><guid isPermaLink="true">https://lifeloinmg.github.io/huwencheng.github.io/post/ce-shi-duo-ji-mu-lu-xin-xi.html</guid><pubDate>Mon, 23 Mar 2026 11:12:28 +0000</pubDate></item><item><title>创建型设计模式</title><link>https://lifeloinmg.github.io/huwencheng.github.io/post/chuang-jian-xing-she-ji-mo-shi.html</link><description>`创建型设计模式：关注对象的创建过程
单例模式、工厂方法模式、抽象工厂模式、建造者模式、原型模式`
#  一、单例模式
表示全局唯一    处理资源访问冲突
## 1、实现方式
### 1.1、饿汉式
在类加载的时候初始化静态变量
```
public class EagerSingleton {  
    private static Singleton instance = new Singleton();  
    private Singleton (){}  
    public static Singleton getInstance() {  
        return instance;  
    }  
}
```
### 1.2、懒汉式
在获取对象的时候进行加载，面对大量并发请求的时候加锁会降低获取单例对象的并发度
```public class Singleton {  
    private static Singleton instance;  
    private Singleton (){}  
    public synchronized static Singleton getInstance() {  
        if (instance == null) {  
            instance = new Singleton();  
        }  
        return instance;  
    }  
}
```
### 1.3、双重检查锁
既支持延迟加载、又支持高并发的单例实现方式；

&lt;img width='1056' height='494' alt='Image' src='https://github.com/user-attachments/assets/41d75a21-f76d-4042-bbc5-b2cb9293eec5' /&gt;

volatile：不稳定、无定形
在Java中修饰变量可确保一个线程修改该变量的值后，修改后的新值是对其他线程是立即可见的
工作内存是CPU的缓存区，多线程操作的时候，线程访问自己的工作内存
加上关键词volatile保证**可见性**
```
public class DclSingleton {  
    private volatile static Singleton singleton;  
    private Singleton (){}  

    public static Singleton getInstance() {  
        if (singleton == null) {  
            synchronized (Singleton.class) {  
                if (singleton == null) {  
                    singleton = new Singleton();  
                }  
            }  
        }  
        return singleton;  
    }  
}
```
### 1.4、静态内部类
 Java 的静态内部类;类 Singleton被加载的时候
SingletonHolder 这个静态内部类，只会在第一次被使用时加载并初始化；
JVM 在执行类的 &lt;clinit&gt;() 方法时，会加锁、同步，确保多线程下也只执行一次。</description><guid isPermaLink="true">https://lifeloinmg.github.io/huwencheng.github.io/post/chuang-jian-xing-she-ji-mo-shi.html</guid><pubDate>Mon, 23 Mar 2026 11:06:54 +0000</pubDate></item><item><title>设计原则</title><link>https://lifeloinmg.github.io/huwencheng.github.io/post/she-ji-yuan-ze.html</link><description># 一、为什么要学习设计模式？
## 1、提高设计和开发能力，不写烂代码
在软件开发中，“能跑起来” 只是基础，“能长期跑好、易迭代” 才是关键。</description><guid isPermaLink="true">https://lifeloinmg.github.io/huwencheng.github.io/post/she-ji-yuan-ze.html</guid><pubDate>Mon, 23 Mar 2026 10:54:46 +0000</pubDate></item></channel></rss>