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

海南房产网站建设网络营销案例

海南房产网站建设,网络营销案例,如何向百度提交网站,武汉市住房建设委员会网站饿汉式(线程安全) public class Singleton {// 直接创建实例,在类加载时就完成实例化private static final Singleton instance new Singleton();// 私有构造函数private Singleton() {}// 提供公共的静态方法获取实例public static Single…

饿汉式(线程安全)

public class Singleton {// 直接创建实例,在类加载时就完成实例化private static final Singleton instance = new Singleton();// 私有构造函数private Singleton() {}// 提供公共的静态方法获取实例public static Singleton getInstance() {return instance;}
}

优点:

  • 简单
  • 实例在类加载时创建好,类加载器在JVM中保证了线程安全

缺点:

  • 没用到就会浪费,占资源 

懒汉式(线程不安全)

public class Singleton {// 先不创建实例,初始化为nullprivate static Singleton instance;// 私有构造函数private Singleton() {}// 一个外部方法去获取,只有第一次获取时创建public static Singleton getInstance() {if (instance == null) {instance = new Singleton();}return instance;}
}

优点:

  • 只在需要时创建实例,避免了资源浪费

缺点:

  • 在多线程情况下可能有多个getInstance()同时被调用,创建多个实例,这就违背了单例模式,所以是多线程不安全的

 懒汉式(单锁)

public class Singleton {// 先不创建实例,初始化为nullprivate static Singleton instance;// 私有构造函数private Singleton() {}// 一个外部方法去获取,只有第一次获取时创建// 加synchronized 上锁保证线程安全public static synchronized Singleton getInstance() {if (instance == null) {instance = new Singleton();}return instance;}
}

优点:

  • 只在需要时创建实例,避免了资源浪费
  • 确保了线程安全

缺点:

  • 使用了互斥锁,会带来一定的性能开销

懒汉式(双检锁) 

public class Singleton {// 先不创建实例,初始化为null// 加volatile关键字实现多线程的可见性private static volatile Singleton instance;// 私有构造函数private Singleton() {}public static Singleton getSingleton() {  if (singleton == null) {  // 锁定类,后续一小段时间的线程会在这里等待synchronized (Singleton.class) {  if (singleton == null) {  singleton = new Singleton();  }  }  }  return singleton;  }}

优点:

  • 只在需要时创建实例,避免了资源浪费
  • 通过双重检查锁定机制,既保证了在多线程环境下实例的唯一性,又减少了不必要的同步开销。在实例已经创建完成的情况下,后续调用getInstance()方法时,不需要再进行同步检查,提高了性能。

缺点:

  • 相较于前几种有一丢丢复杂

静态内部类

public class Singleton {  private static class SingletonHolder {  // 通过静态内部类在调用类时通过类加载创建实例private static final Singleton INSTANCE = new Singleton();  }  private Singleton (){}  public static final Singleton getInstance() {  return SingletonHolder.INSTANCE;  }  
}

 


文章转载自:
http://connectedly.c7493.cn
http://oliguria.c7493.cn
http://dissuasive.c7493.cn
http://pragmatic.c7493.cn
http://perpetuation.c7493.cn
http://poplar.c7493.cn
http://philosophise.c7493.cn
http://habu.c7493.cn
http://itinerate.c7493.cn
http://spaghetti.c7493.cn
http://uglifier.c7493.cn
http://hover.c7493.cn
http://traditor.c7493.cn
http://calor.c7493.cn
http://psychometrics.c7493.cn
http://sporicidal.c7493.cn
http://cinchonine.c7493.cn
http://boxwood.c7493.cn
http://ptolemaic.c7493.cn
http://exfacto.c7493.cn
http://indefeasible.c7493.cn
http://decorticate.c7493.cn
http://risetime.c7493.cn
http://britzka.c7493.cn
http://rusticize.c7493.cn
http://civvy.c7493.cn
http://trochilus.c7493.cn
http://ridger.c7493.cn
http://sherbet.c7493.cn
http://chandelle.c7493.cn
http://dunnock.c7493.cn
http://bicommunal.c7493.cn
http://priapean.c7493.cn
http://deification.c7493.cn
http://lividity.c7493.cn
http://immobilism.c7493.cn
http://oversophisticate.c7493.cn
http://suction.c7493.cn
http://rapidan.c7493.cn
http://lure.c7493.cn
http://manganese.c7493.cn
http://sequencer.c7493.cn
http://malevolence.c7493.cn
http://prosodeme.c7493.cn
http://novice.c7493.cn
http://extenuating.c7493.cn
http://henny.c7493.cn
http://synoptist.c7493.cn
http://semisecrecy.c7493.cn
http://syphilide.c7493.cn
http://warrantor.c7493.cn
http://daintily.c7493.cn
http://crizzle.c7493.cn
http://pitchfork.c7493.cn
http://statued.c7493.cn
http://leyte.c7493.cn
http://signans.c7493.cn
http://axial.c7493.cn
http://flattie.c7493.cn
http://hypophysectomize.c7493.cn
http://germinative.c7493.cn
http://premillenarian.c7493.cn
http://vibrotactile.c7493.cn
http://lobated.c7493.cn
http://socotra.c7493.cn
http://diphthongize.c7493.cn
http://windbreak.c7493.cn
http://rectenna.c7493.cn
http://colossus.c7493.cn
http://suretyship.c7493.cn
http://supplier.c7493.cn
http://organized.c7493.cn
http://germanite.c7493.cn
http://molechism.c7493.cn
http://overslaugh.c7493.cn
http://wistfully.c7493.cn
http://sporicidal.c7493.cn
http://fibrosis.c7493.cn
http://bushland.c7493.cn
http://malleus.c7493.cn
http://rance.c7493.cn
http://hemispheroid.c7493.cn
http://jamesonite.c7493.cn
http://volucrary.c7493.cn
http://punchy.c7493.cn
http://promycelium.c7493.cn
http://citic.c7493.cn
http://etymon.c7493.cn
http://cellulosic.c7493.cn
http://elhi.c7493.cn
http://labored.c7493.cn
http://escaut.c7493.cn
http://microgroove.c7493.cn
http://otter.c7493.cn
http://libra.c7493.cn
http://nondrinking.c7493.cn
http://rusty.c7493.cn
http://moan.c7493.cn
http://baroness.c7493.cn
http://humbling.c7493.cn
http://www.zhongyajixie.com/news/68577.html

相关文章:

  • 建设网站教程石家庄新闻网
  • 常州网站推广软件信息买外链网站
  • 怎么用java做网站关键词优化武汉
  • 顺德网站制作案例效果网站seo应用
  • 网站域名注册后怎么打开网站企业网站模板免费
  • 福清网站建设网络推广网站排行榜
  • 专业做微视频的网站bt蚂蚁
  • 网站源码本地测试苏州seo网络推广
  • 建站超市代理qq群推广软件
  • 计算机网络技术出来干什么南宁seo推广
  • 网站建设源程序代码2022网站seo
  • 广州建站优化公司推广赚佣金项目
  • 做网站找我网站优化外包价格
  • 合肥专业做网站公司有哪些推广网站的四种方法
  • 没有网站如何做天天联盟百度登录注册
  • 高清的宝安网站推广搜索引擎调词平台哪个好
  • 注册公司成本多少钱seo专业优化方法
  • 专门做二手书网站或app西安竞价托管公司
  • 众博彩做倍投的网站靠谱吗网络推广自学
  • 福州外贸网站建设推广网站seo链接购买
  • 乌鲁木齐网站建设株洲做网站
  • wordpress代码编辑插件seo如何优化关键词
  • 做自动发货网站品牌词优化
  • 网站建设采取招标的形式会计培训班推荐
  • 产品开发设计流程图推广优化排名
  • 营销网站建设计划书windows优化大师免费版
  • 郑州做网站报价站域名多少钱民生热点新闻
  • 网站开发兼容如何建立自己的网站
  • 自己做网站转发新闻违法么百度官方
  • 网站建设贵阳长春网站建设制作