单例模式
单例模式
只是实例化一次,只有一个对象
饿汉式
1 | //饿汉式:先创建好,没有线程安全问题 懒汉式:懒得创建好,你要我就创建,不过要考虑线程安全问题 |
懒汉式
1 | // 懒汉式的设计模式一般使用双检查锁和原子化的方式来解决线程安全的问题 |
图示
// TODO
// 后面会加上UML的截图
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 YaCo!
评论
只是实例化一次,只有一个对象
1 | //饿汉式:先创建好,没有线程安全问题 懒汉式:懒得创建好,你要我就创建,不过要考虑线程安全问题 |
1 | // 懒汉式的设计模式一般使用双检查锁和原子化的方式来解决线程安全的问题 |
// TODO
// 后面会加上UML的截图