首页 > 应用开发 > C/C++ > 小视频源码,设计模式单例模式
小视频源码,设计模式单例模式实现的相关代码
一. 单线程时候推荐
/** * Created by Shinelon on 2018/10/11. * 单利模式 懒汉式 -->单线程推荐使用 */ public final class Singleton { public static Singleton instance; private Singleton(){ } public static Singleton getInstance(){ if(instance == null){ instance = new Singleton(); } return instance; } }
二, 多线程推荐
/** * Created by Shinelon on 2018/10/11. * 单例模式 静态内部类 多线程的情况下推荐 */ public final class Singleton { private Singleton(){ } public static Singleton getInstance(){ return SingletonHolde.singleton; } public static class SingletonHolde{ private static Singleton singleton = new Singleton(); } }
以上就是小视频源码,设计模式单例模式实现的相关代码, 更多内容欢迎关注之后的文章
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69978258/viewspace-2749665/,如需转载,请注明出处,否则将追究法律责任。