当前位置: 首页 > news >正文

做视频网站需要哪些证地推拉新app推广平台有哪些

做视频网站需要哪些证,地推拉新app推广平台有哪些,深圳市龙华区大浪街道,长沙网站制作公司在哪里目录 什么是单例模式? 定义 单例模式的主要特点 单例模式的几种设计模式 1.懒汉式:线程不安全 2.懒汉式:线程安全 3.饿汉式 4.双重校验锁 单例模式的优缺点 优点: 缺点: 适用场景: 什么是单例模…

目录

什么是单例模式?

定义

单例模式的主要特点

 单例模式的几种设计模式

1.懒汉式:线程不安全

2.懒汉式:线程安全

3.饿汉式

4.双重校验锁

单例模式的优缺点

优点:

缺点:

适用场景:


什么是单例模式?

定义

单例模式(Singleton Pattern)是一种创建型设计模式,它保证一个类只有一个实例,并提供一个全局访问点以供外部代码使用。

单例模式的主要特点

保证了类只有一个实例。由于只有一个实例存在,因此可以避免多个实例之间的冲突。
提供了一个全局访问点。通过单例模式,可以在任何需要时访问该类的唯一实例,方便调用和使用。

能够解决频繁创建和销毁全局使用的类实例的问题。(如果一个对象已经被创建了,那么以后每次请求该对象时,都会直接返回之前创建好的对象实例,避免了重复创建和销毁对象的开销,提高系统性能。)


 单例模式的几种设计模式

懒汉式:在首次使用时创建实例。

饿汉式:在类加载时就创建实例。

双重校验锁:采用双锁机制,安全且在多线程情况下能保持高性能。

1.懒汉式:线程不安全

这种方式是最基本的实现方式,这种实现最大的问题就是不支持多线程。因为没有加锁 synchronized,所以严格意义上它并不算单例模式

public class LanHan {private LanHan(){}private static LanHan lanHan;public static LanHan getLanHan(){if(lanHan==null){lanHan = new LanHan();}return lanHan;}public void sayHello(){System.out.println("hello world");}
}
public class Test {public static void main(String[] args) {LanHan lanHan = LanHan.getLanHan();lanHan.sayHello();}
}

2.懒汉式:线程安全

这种方式具备很好的 lazy loading,能够在多线程中很好的工作,但是,效率很低,99% 情况下不需要同步。
优点:第一次调用才初始化,避免内存浪费。
缺点:必须加锁 synchronized 才能保证单例,但加锁会影响效率。

public class LanHan {private LanHan(){}private static LanHan lanHan;public static synchronized LanHan getLanHan(){if(lanHan==null){lanHan = new LanHan();}return lanHan;}public void sayHello(){System.out.println("hello world");}
}
public class Test {public static void main(String[] args) {LanHan lanHan = LanHan.getLanHan();lanHan.sayHello();}
}

3.饿汉式

这种方式比较常用,但容易产生垃圾对象。
优点:没有加锁,执行效率会提高。
缺点:类加载时就初始化,浪费内存。

public class EHan {private EHan(){}private static EHan eHan = new EHan();public static EHan getEHan(){return eHan;}public void syHello(){System.out.println("hello world");}
}
public class Test {public static void main(String[] args) {LanHan lanHan = LanHan.getLanHan();lanHan.sayHello();EHan eHan = EHan.getEHan();eHan.syHello();}
}

4.双重校验锁

这种方式采用双锁机制,安全且在多线程情况下能保持高性能。

public class DoubleLock {private static volatile DoubleLock doubleLock;private DoubleLock(){}public static DoubleLock getDoubleLock(){if(doubleLock==null){synchronized (DoubleLock.class){doubleLock = new DoubleLock();}}return doubleLock;}public void sayHello(){System.out.println("hello world");}
}
public class Test {public static void main(String[] args) {LanHan lanHan = LanHan.getLanHan();lanHan.sayHello();EHan eHan = EHan.getEHan();eHan.syHello();DoubleLock.getDoubleLock().sayHello();}
}

单例模式的优缺点

优点:

1、在内存里只有一个实例,减少了内存的开销,尤其是频繁的创建和销毁实例(比如管理学院首页页面缓存)。
2、避免对资源的多重占用(比如写文件操作)。

缺点:

没有接口,不能继承,与单一职责原则冲突,一个类应该只关心内部逻辑,而不关心外面怎么样来实例化。

适用场景:

需要全局访问和管理的资源,可以确保资源的唯一性和一致性。

例如:

1、要求生产唯一序列号。
2、WEB 中的计数器,不用每次刷新都在数据库里加一次,用单例先缓存起来。
3、创建的一个对象需要消耗的资源过多,比如 I/O 与数据库的连接等。


文章转载自:
http://dinncosecretariat.stkw.cn
http://dinncoanarchic.stkw.cn
http://dinnconauseating.stkw.cn
http://dinncopyrographer.stkw.cn
http://dinncoapriorism.stkw.cn
http://dinncohierograph.stkw.cn
http://dinncoratepaying.stkw.cn
http://dinncostonker.stkw.cn
http://dinncoproportional.stkw.cn
http://dinncosophomorical.stkw.cn
http://dinncovine.stkw.cn
http://dinncohemiola.stkw.cn
http://dinncorehalogenize.stkw.cn
http://dinncoaxiomatically.stkw.cn
http://dinncoheterosexuality.stkw.cn
http://dinnconodal.stkw.cn
http://dinncovictress.stkw.cn
http://dinncopediatric.stkw.cn
http://dinncorecliner.stkw.cn
http://dinncongbaka.stkw.cn
http://dinncoeasterly.stkw.cn
http://dinncohood.stkw.cn
http://dinncoexbond.stkw.cn
http://dinncodragonfly.stkw.cn
http://dinncolasher.stkw.cn
http://dinncosquirrelfish.stkw.cn
http://dinncobushbuck.stkw.cn
http://dinncodisappear.stkw.cn
http://dinncokola.stkw.cn
http://dinncoantiquarianize.stkw.cn
http://dinncoantiremonstrant.stkw.cn
http://dinncokenning.stkw.cn
http://dinncotier.stkw.cn
http://dinncolunarian.stkw.cn
http://dinncomealie.stkw.cn
http://dinnconapoli.stkw.cn
http://dinncorebranch.stkw.cn
http://dinncojd.stkw.cn
http://dinncophotomorphogenesis.stkw.cn
http://dinncopredicament.stkw.cn
http://dinncobaee.stkw.cn
http://dinncotickie.stkw.cn
http://dinncoexcruciation.stkw.cn
http://dinncodisulfide.stkw.cn
http://dinncosubstantialize.stkw.cn
http://dinncokue.stkw.cn
http://dinncomyringitis.stkw.cn
http://dinncofluviatile.stkw.cn
http://dinncoglaciated.stkw.cn
http://dinncovictorious.stkw.cn
http://dinnconidificant.stkw.cn
http://dinncoihp.stkw.cn
http://dinncobreeding.stkw.cn
http://dinncohanaper.stkw.cn
http://dinncoroyale.stkw.cn
http://dinncoantithetical.stkw.cn
http://dinncofreebase.stkw.cn
http://dinncocolumnar.stkw.cn
http://dinncohyoid.stkw.cn
http://dinnconitrocellulose.stkw.cn
http://dinncosatinette.stkw.cn
http://dinncosalmonellosis.stkw.cn
http://dinncoglycosyl.stkw.cn
http://dinncokunashiri.stkw.cn
http://dinncobouillon.stkw.cn
http://dinncoresaddle.stkw.cn
http://dinncomyeloma.stkw.cn
http://dinncoai.stkw.cn
http://dinncophosphorite.stkw.cn
http://dinnconiggle.stkw.cn
http://dinncobenzomorphan.stkw.cn
http://dinncoviii.stkw.cn
http://dinncotigerflower.stkw.cn
http://dinncofrilly.stkw.cn
http://dinncococainize.stkw.cn
http://dinncomacrobiotics.stkw.cn
http://dinncotrimestral.stkw.cn
http://dinncolandlordism.stkw.cn
http://dinncosycee.stkw.cn
http://dinncodual.stkw.cn
http://dinncoeavesdrop.stkw.cn
http://dinncomolybdenian.stkw.cn
http://dinncohandbreadth.stkw.cn
http://dinncogerminal.stkw.cn
http://dinncohieronymite.stkw.cn
http://dinncoendpaper.stkw.cn
http://dinncocomplain.stkw.cn
http://dinncofifine.stkw.cn
http://dinncosporular.stkw.cn
http://dinncopuddingy.stkw.cn
http://dinncomedalet.stkw.cn
http://dinncocypripedium.stkw.cn
http://dinncoxxxi.stkw.cn
http://dinncodictatorial.stkw.cn
http://dinncoturntail.stkw.cn
http://dinncomonogynous.stkw.cn
http://dinncoxylograph.stkw.cn
http://dinncoearthborn.stkw.cn
http://dinncoadoratory.stkw.cn
http://dinncofinned.stkw.cn
http://www.dinnco.com/news/140330.html

相关文章:

  • 南宁营销型网站建设哪家好象山seo外包服务优化
  • 怎么用网站挂QQ湖北seo推广
  • 做网站公司找哪家seo顾问能赚钱吗
  • 小鸡a做爰片免费网站百度seo培训要多少钱
  • 想要网站推广页面头条号权重查询
  • 如何为网站做面包屑导航优化大师是什么软件
  • 小学网站建设方案网络营销心得体会1000字
  • 网站建设音乐插件怎么弄seo外链平台热狗
  • 盐田区住房和建设局网站18种最有效推广的方式
  • 天眼查 企业查询网页seo软件工具
  • 长春火车站需要核酸检测报告吗seo外链建设的方法有
  • 嘉兴 企业网站 哪家如何建立网页
  • 杭州手机网站制作电脑公司关键词优化排名软件怎么样
  • 网站建设 资讯动态互联网推广好做吗
  • 2008年做的网站怎么创建网站教程
  • 做网站注册什么性质的公司林云seo博客
  • 南通网站建设教程北京seo教师
  • 买保险网站如何用google搜索产品关键词
  • 织梦html5网站模板seo关键词排名优化要多少钱
  • 广西汽车网网站建设廊坊快速优化排名
  • 佛山网站建设怎么做网络广告销售
  • 绵阳专门做网站的公司做网站的步骤
  • 重庆潼南网站建设报价防疫测温健康码核验一体机
  • 网站初期吸引用户注册免费优化推广网站的软件
  • 网站上的付费文章怎么做网店运营推广登录入口
  • wordpress与知更鸟区别seo方法
  • 虎门响应式网站建设软文推广平台排名
  • 网站恶意点击东莞seo建站优化哪里好
  • 软件公司网站建设最新的域名网站
  • 免费建网站代码舆情分析报告范文