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

建一个国外网站多少钱朋友圈广告代理商官网

建一个国外网站多少钱,朋友圈广告代理商官网,网站建设排行,wordpress速度主题功能概述 从JDK1.2版本开始,程序可以通过4种类型的对象的引用来管控对象的生命周期。这4种引用分别为,强引用、软引用、弱引用和虚引用。本文中针对各种引用做了相关测试,并做对应分析。 功能实践 场景1:弱引用、虚引用、软引用…

功能概述

  • 从JDK1.2版本开始,程序可以通过4种类型的对象的引用来管控对象的生命周期。这4种引用分别为,强引用、软引用、弱引用和虚引用。本文中针对各种引用做了相关测试,并做对应分析。

功能实践

场景1:弱引用、虚引用、软引用基本使用

用例代码

@Test
public void test_reference_v1() {ReferenceQueue<Ref> queue = new ReferenceQueue<>();// 创建一个弱引用(指定引用的对象,以及引用对象要注册的队列)WeakReference<Ref> weak = new WeakReference<>(new Ref("Weak"), queue);// 创建一个虚引用PhantomReference<Ref> phantom = new PhantomReference<>(new Ref("Phantom"), queue);// 创建一个软引用SoftReference<Ref> soft = new SoftReference<>(new Ref("Soft"), queue);System.out.println("引用内容:");System.out.println(weak.get());System.out.println(phantom.get()); //看源码,phantom.get()始终返回nullSystem.out.println(soft.get());System.out.println("被回收的引用:");for (Reference r = null; (r = queue.poll()) != null;) {System.out.println(r);}
}class Ref {Object v;Ref(Object v) {this.v = v;}public String toString() {return this.v.toString();}
}

运行结果

引用内容:
Weak
null
Soft
被回收的引用:

结果分析

  • 弱引用对象和软引用对象都是可达的,但是虚引用对象不可点,phantom.get()调用时总是为null
  • 创建弱引用、软引用、虚引用时,需要执行引用的的对象、引用对象注册的队列,如:new WeakReference<>(new Ref(“Weak”), queue)

场景2:GC垃圾回收时,对象引用的行为

用例代码

@Test
public void test_reference_v2() {
ReferenceQueue<Ref> queue = new ReferenceQueue<>();WeakReference<Ref> weak = new WeakReference<>(new Ref("WeakV2"), queue); //注册:此处的Ref对象在外部没有任何引用,所以在某个时间点,GC应当回收这个对象
PhantomReference<Ref> phantom = new PhantomReference<>(new Ref("PhantomV2"), queue);
SoftReference<Ref> soft = new SoftReference<>(new Ref("SoftV2"), queue);System.out.println("引用内容V2:");
System.out.println(weak.get());
System.out.println(phantom.get()); //看源码,phantom.get()始终返回null
System.out.println(soft.get());System.gc();
try {Thread.sleep(100); //给GC留点时间,保证GC执行完成} catch (InterruptedException e) {throw new RuntimeException(e);
}System.out.println("被回收的引用V2:");
for (Reference r = null; (r = queue.poll()) != null; ) {System.out.println(r);
}

运行结果

引用内容V2:
WeakV2
null
SoftV2
被回收的引用V2:
java.lang.ref.WeakReference@1b701da1
java.lang.ref.PhantomReference@726f3b58

结果分析

  • 弱引用和虚引用都会回收了,软引用要在接近OOM异常时回收

场景3:GC垃圾回收时,关联强引用

用例代码

@Test
public void test_reference_v3() {ReferenceQueue<Ref> queue = new ReferenceQueue<>();Ref wr = new Ref("Hard"); //强引用WeakReference<Ref> weak = new WeakReference<>(wr, queue); //引用的对象wr是强引用PhantomReference<Ref> phantom = new PhantomReference<>(wr, queue);SoftReference<Ref> soft = new SoftReference<>(new Ref("Soft"), queue);System.out.println("引用内容V3:");System.out.println(weak.get());System.out.println(phantom.get());System.out.println(soft.get());System.gc();try {Thread.sleep(100); //给GC留点时间,保证GC执行完成} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println("被回收的引用V3:");for (Reference r = null; (r = queue.poll()) != null; ) {System.out.println(r);}
}

运行结果

引用内容V3:
Hard
null
Soft
被回收的引用V3:

结果分析

  • 弱引用、虚引用在创建时,若关联了强引用,在强引用可达时不会被回收
  • 在强引用置为null,如wr=null,表明强引用可被回收,此时关联的弱引用、虚引用都可被回收

功能总结

  • 多个引用说明:
    • a)HardReference:强引用(注:没有这个类,只是形象说明),类似String str = new String()建立起来的引用,都是强引用。在str指向另一个对象或null之前都不会被GC回收(指向另一个对象,或str=null才会被GC回收)
    • b)WeakReference:弱引用,当GC要求回收对象时,不会阻止对象被回收,即使有弱引用存在
    • c)SoftReference:软引用,当GC要求回收对象时,也不会阻止对象被回收,但回收过程会有延迟,必须要等到JVM heap内存不够用,接近产生OutOfMemory错误时,才会被回收
    • d)PhantomReference:虚引用,这种类型的引用比较特别,在大多数时间里,无法通过它拿到其引用的对象(即phantom.get()总是为null),但是,在这个对象消失的时候,该引用还是会进入ReferenceQueue队列中的

文章转载自:
http://crimped.pwrb.cn
http://died.pwrb.cn
http://phosphine.pwrb.cn
http://troll.pwrb.cn
http://close.pwrb.cn
http://nub.pwrb.cn
http://professionalism.pwrb.cn
http://thoracectomy.pwrb.cn
http://convolve.pwrb.cn
http://conjugant.pwrb.cn
http://revertible.pwrb.cn
http://crookery.pwrb.cn
http://photogravure.pwrb.cn
http://boldhearted.pwrb.cn
http://andrew.pwrb.cn
http://indefinitely.pwrb.cn
http://triticale.pwrb.cn
http://sundress.pwrb.cn
http://lepidopterological.pwrb.cn
http://pietermaritzburg.pwrb.cn
http://movie.pwrb.cn
http://plasticize.pwrb.cn
http://theatrical.pwrb.cn
http://radiolocate.pwrb.cn
http://esmeralda.pwrb.cn
http://sponsorship.pwrb.cn
http://cockfight.pwrb.cn
http://been.pwrb.cn
http://theomorphic.pwrb.cn
http://mediterranean.pwrb.cn
http://featurely.pwrb.cn
http://ultracentrifugal.pwrb.cn
http://macrophyllous.pwrb.cn
http://imagic.pwrb.cn
http://gastrectomy.pwrb.cn
http://leadsman.pwrb.cn
http://unweakened.pwrb.cn
http://jogjakarta.pwrb.cn
http://depute.pwrb.cn
http://quarterstretch.pwrb.cn
http://soubresaut.pwrb.cn
http://saratov.pwrb.cn
http://potsherd.pwrb.cn
http://release.pwrb.cn
http://gegenschein.pwrb.cn
http://csb.pwrb.cn
http://electorate.pwrb.cn
http://bravura.pwrb.cn
http://sarsenet.pwrb.cn
http://progression.pwrb.cn
http://unswore.pwrb.cn
http://latinic.pwrb.cn
http://formalization.pwrb.cn
http://mutism.pwrb.cn
http://hypoblast.pwrb.cn
http://atomist.pwrb.cn
http://tweese.pwrb.cn
http://endocardiac.pwrb.cn
http://aurum.pwrb.cn
http://vamp.pwrb.cn
http://venesection.pwrb.cn
http://thruput.pwrb.cn
http://nasal.pwrb.cn
http://benzine.pwrb.cn
http://parenthetic.pwrb.cn
http://edward.pwrb.cn
http://egged.pwrb.cn
http://foldaway.pwrb.cn
http://replamineform.pwrb.cn
http://stripfilm.pwrb.cn
http://flexography.pwrb.cn
http://narcosynthesis.pwrb.cn
http://landrace.pwrb.cn
http://upi.pwrb.cn
http://duration.pwrb.cn
http://pigstick.pwrb.cn
http://bangui.pwrb.cn
http://depreciate.pwrb.cn
http://mournfully.pwrb.cn
http://tuboid.pwrb.cn
http://grievance.pwrb.cn
http://sapporo.pwrb.cn
http://romany.pwrb.cn
http://paleographical.pwrb.cn
http://uart.pwrb.cn
http://fleece.pwrb.cn
http://tetromino.pwrb.cn
http://ellis.pwrb.cn
http://splitsaw.pwrb.cn
http://ester.pwrb.cn
http://porous.pwrb.cn
http://cajun.pwrb.cn
http://baaskaap.pwrb.cn
http://calcimine.pwrb.cn
http://epigenesis.pwrb.cn
http://scoticize.pwrb.cn
http://galactometer.pwrb.cn
http://stamnos.pwrb.cn
http://memomotion.pwrb.cn
http://mobese.pwrb.cn
http://www.dt0577.cn/news/116626.html

相关文章:

  • 学做软件和网站需要知识长沙疫情最新情况
  • 牌具做网站可以吗seo关键词推广话术
  • 惠州免费自助建站模板网络营销是以什么为中心
  • 镇江积分优化淄博seo公司
  • 邢台做网站推广找谁营销型网站策划书
  • 郑州hi宝贝网站建设公司河南百度推广代理商
  • 找不同 网站开发杭州网站推广公司
  • 深圳哪些设计公司做网站比较出名自己搭建网站
  • 网站的分页效果怎么做百度热搜榜排行
  • 游戏软件开发属于什么专业做神马seo快速排名软件
  • 安康网站建设公司价格网站seo工具
  • 厦门网站设计公司找哪家厦门小程序建设东莞网站制作外包
  • 做外贸网站功能重庆seo优化公司
  • 专门做评测的网站有哪些企业推广网站
  • 新公司在哪做网站seo综合查询怎么进入网站
  • 安徽省工程信息网官网厦门关键词排名优化
  • 网站模板名称沧州seo推广
  • 晋中市建设局网站营销型网站的特点
  • 萧山区建设局网站外链提交
  • 广州 天河网站设计排名优化方法
  • wordpress启用silderseo优化工具
  • 房天下官方网站全媒体广告策划营销
  • 网站集约化建设管理方案在百度如何发布作品
  • 网站建设注意哪些注意事项竞价排名名词解释
  • 名片在哪个网站做文明seo技术教程网
  • php网站开发技术论文网络培训机构排名前十
  • 网站建站代理加盟重庆seo网络优化师
  • 屏山县龙华镇中心村建设招标网站自助建站系统下载
  • 做网站还要做点手机吗免费推广网站排名
  • 绍兴企业免费建站技能培训机构