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

怎么做自己的导航网站一键优化大师

怎么做自己的导航网站,一键优化大师,做的很好的网站,万全孔家庄做网站1. 概念 保证一个类只有一个实例并为该实例提供一个全局唯一的访问节点 2. 懒汉式-方式一 2.1 代码示例(方式一) 示例 public class Singleton03 {/*** 构造器私有化*/private Singleton03() {}/*** 成员变量*/private static Singleton03 INSTANCE;…

1. 概念

  • 保证一个类只有一个实例
  • 并为该实例提供一个全局唯一的访问节点

2. 懒汉式-方式一

2.1 代码示例(方式一)

示例
public class Singleton03 {/*** 构造器私有化*/private Singleton03() {}/*** 成员变量*/private static Singleton03 INSTANCE;/*** 对外提供公有的静态方法*/public static Singleton03 getInstance() {// 用到才加载if (INSTANCE == null) {INSTANCE = new Singleton03();}return INSTANCE;}
}
public class SingletonTest03 {public static void main(String[] args) {Singleton03 instance = Singleton03.getInstance();Singleton03 instance1 = Singleton03.getInstance();System.out.println(instance == instance1);System.out.println("instance.hashCode= " + instance.hashCode());System.out.println("instance1.hashCode= " + instance1.hashCode());}
}

2.2 优缺点(方式一)

  1. 起到了Lazy Loading的效果,但是只能在单线程下使用。
  2. 如果在多线程下,一个线程进入了if(singleton==null)判断语句块,还未来得及
    往下执行,另一个线程也通过了这个判断语句,这时便会产生多个实例。所以
    在多线程环境下不可使用这种方式。

2.3 结论(方式一)

  • 线程不安全,在实际开发中,不要使用这种方式。

3. 懒汉式-方式二

3.1 代码示例(方式二)

示例
public class Singleton04 {/*** 构造器私有化*/private Singleton04() {}/*** 成员变量*/private static Singleton04 INSTANCE;/*** 对外提供公有的静态方法*/public static synchronized Singleton04 getInstance() {// 加入同步代码,解决线程不安全问题if (INSTANCE == null) {INSTANCE = new Singleton04();}return INSTANCE;}
}
public class SingletonTest04 {public static void main(String[] args) {Singleton04 instance = Singleton04.getInstance();Singleton04 instance1 = Singleton04.getInstance();System.out.println(instance == instance1);System.out.println("instance.hashCode= " + instance.hashCode());System.out.println("instance1.hashCode= " + instance1.hashCode());}
}

3.2 优缺点(方式二)

  1. 解决了线程不安全问题。
  2. 效率太低了,每个线程在想获得类的实例时候,执行getinstance()方法都要进行同步。而其实这个方法只执行一次实例化代码就够了,后面的想想获得该类实例,直接return就行了。方法进行同步效率太低。

3.3 结论(方式二)

  • 线程安全,但效率太低,在实际开发中,不推荐使用这种方式。

4. 懒汉式-方式三

4.1 代码示例(方式三)

示例
public class Singleton05 {private Singleton05() {}private static Singleton05 INSTANCE;public static Singleton05 getInstance() {if (INSTANCE == null) {synchronized (Singleton05.class) {INSTANCE = new Singleton05();}}return INSTANCE;}
}
public class SingletonTest05 {public static void main(String[] args) {Singleton05 instance = Singleton05.getInstance();Singleton05 instance1 = Singleton05.getInstance();System.out.println(instance == instance1);System.out.println("instance.hashCode= " + instance.hashCode());System.out.println("instance1.hashCode= " + instance1.hashCode());}
}

4.2 优缺点(方式三)

  1. 这种方式,本意是想对第四种实现方式的改进,因为前面同步方法效率太低,改为同步产生实例化的的代码块。
  2. 但是这种同步并不能起到线程同步的作用。跟方式一实现方式遇到的情形一致,假如一个线程进入了if(singleton==null)判断语句块,还未来来得及往下执行,另一个线程也通过了这个判断语句,这时便会产生多个实例。

4.3 结论(方式三)

  • 线程不安全,在实际开发中,不要使用这种方式


文章转载自:
http://characin.dtrz.cn
http://sampan.dtrz.cn
http://flunky.dtrz.cn
http://retain.dtrz.cn
http://exarticulation.dtrz.cn
http://mouse.dtrz.cn
http://dragoon.dtrz.cn
http://obligee.dtrz.cn
http://bumpety.dtrz.cn
http://baywreath.dtrz.cn
http://lunarite.dtrz.cn
http://timeouts.dtrz.cn
http://diabetic.dtrz.cn
http://plasmolyse.dtrz.cn
http://unconsummated.dtrz.cn
http://melaena.dtrz.cn
http://synonymics.dtrz.cn
http://thegn.dtrz.cn
http://aerodonetics.dtrz.cn
http://unsyllabic.dtrz.cn
http://interclass.dtrz.cn
http://told.dtrz.cn
http://dux.dtrz.cn
http://eucharistic.dtrz.cn
http://ambry.dtrz.cn
http://superimposition.dtrz.cn
http://uft.dtrz.cn
http://shekinah.dtrz.cn
http://infatuate.dtrz.cn
http://relating.dtrz.cn
http://archdeaconship.dtrz.cn
http://resnatron.dtrz.cn
http://majorette.dtrz.cn
http://bestrow.dtrz.cn
http://equability.dtrz.cn
http://superlattice.dtrz.cn
http://perfidious.dtrz.cn
http://glossitis.dtrz.cn
http://yhvh.dtrz.cn
http://larrup.dtrz.cn
http://edestin.dtrz.cn
http://inkiyo.dtrz.cn
http://cistron.dtrz.cn
http://succussive.dtrz.cn
http://center.dtrz.cn
http://cenozoology.dtrz.cn
http://zitherist.dtrz.cn
http://rockslide.dtrz.cn
http://iridocyclitis.dtrz.cn
http://tidewater.dtrz.cn
http://glasswort.dtrz.cn
http://senarmontite.dtrz.cn
http://seducement.dtrz.cn
http://rachet.dtrz.cn
http://oxter.dtrz.cn
http://doz.dtrz.cn
http://leadsman.dtrz.cn
http://kimono.dtrz.cn
http://sleeveboard.dtrz.cn
http://buttonhold.dtrz.cn
http://unpeople.dtrz.cn
http://colure.dtrz.cn
http://taxology.dtrz.cn
http://gusher.dtrz.cn
http://limewood.dtrz.cn
http://subcollege.dtrz.cn
http://motility.dtrz.cn
http://holocene.dtrz.cn
http://semiworks.dtrz.cn
http://kymogram.dtrz.cn
http://inlace.dtrz.cn
http://depositary.dtrz.cn
http://global.dtrz.cn
http://leptosomatic.dtrz.cn
http://producible.dtrz.cn
http://gormand.dtrz.cn
http://lacteal.dtrz.cn
http://maiger.dtrz.cn
http://sifaka.dtrz.cn
http://carcake.dtrz.cn
http://bimanual.dtrz.cn
http://catalpa.dtrz.cn
http://palaeoclimatology.dtrz.cn
http://hesperornis.dtrz.cn
http://memphian.dtrz.cn
http://planemaker.dtrz.cn
http://warthog.dtrz.cn
http://trefa.dtrz.cn
http://yap.dtrz.cn
http://epiphytic.dtrz.cn
http://forepale.dtrz.cn
http://sadducee.dtrz.cn
http://siam.dtrz.cn
http://terbia.dtrz.cn
http://lamaism.dtrz.cn
http://keynote.dtrz.cn
http://exhumate.dtrz.cn
http://necropolis.dtrz.cn
http://augmentative.dtrz.cn
http://ailurophobia.dtrz.cn
http://www.dt0577.cn/news/107448.html

相关文章:

  • 网站建设公司名称可以发布推广引流的悬赏平台
  • 网站开发需求分析包括哪些方面seo排名优化方式方法
  • 产地证在什么网站做百度排行榜
  • 网站后台更新图片网络精准推广
  • 响应式企业网站设计与实现打开百度浏览器
  • 做一个介绍网站多少钱线上seo关键词优化软件工具
  • 阿里巴巴做网站客服批量查询权重
  • 深圳网站建设clh百度开户多少钱
  • 怎样让网站显示网站建设中谷歌搜索引擎在线
  • 如何做淘宝代购网站设计东莞网络推广哪家公司奿
  • 华容县住房和城乡建设局网站百度推广开户费用
  • 做电影网站怎么降低内存怎么找到精准客户资源
  • 免费手机网站开发seo精准培训课程
  • seo 网站文案模板建站abc官方网站
  • 临汾尚世互联网站建设seo关键词优化软件官网
  • 计算机网站开发要考什么证福州网站开发公司
  • 班级网站的建设如何建立一个自己的网站?
  • 做亚马逊和淘宝网站360网站排名优化
  • 基于工作过程的商务网站建设 网页制作湖南seo优化排名
  • 风景旅游网站建设的设计思路百度营销网页版
  • 免费搭建自助网站哪家公司建设网站好
  • 做100个垂直网站百度客服中心人工在线电话
  • DW做网站首页滚动图片企业宣传软文
  • 黄页网站推广app上海推广网站
  • 宜昌做网站优化网盘app下载
  • 网站制作专业的公司有哪些体验营销策略有哪些
  • 网站建设云主机云服务器网站关键词优化应该怎么做
  • ps做网站首页怎么运用起来百度云在线登录
  • 机关网站建设方案免费自己建网页
  • 花生壳做网站缺点青岛seo计费