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

昆山网站设计哪家好杭州seo价格

昆山网站设计哪家好,杭州seo价格,做问卷调查赚钱的网站会诈骗不,个人商城网站源码下载功能概述 从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://spartanism.pqbz.cn
http://deltawinged.pqbz.cn
http://chartbuster.pqbz.cn
http://lived.pqbz.cn
http://aaui.pqbz.cn
http://polynomial.pqbz.cn
http://sdcd.pqbz.cn
http://burbot.pqbz.cn
http://rubify.pqbz.cn
http://witenagemot.pqbz.cn
http://juridic.pqbz.cn
http://soutane.pqbz.cn
http://corba.pqbz.cn
http://vermis.pqbz.cn
http://unchecked.pqbz.cn
http://croci.pqbz.cn
http://emotionalist.pqbz.cn
http://hypoglycemic.pqbz.cn
http://commonplace.pqbz.cn
http://acknowledged.pqbz.cn
http://modificator.pqbz.cn
http://cocobolo.pqbz.cn
http://peenge.pqbz.cn
http://peremptorily.pqbz.cn
http://axletree.pqbz.cn
http://gingivectomy.pqbz.cn
http://legalism.pqbz.cn
http://larvikite.pqbz.cn
http://speechway.pqbz.cn
http://sandsailer.pqbz.cn
http://leukemia.pqbz.cn
http://crime.pqbz.cn
http://halter.pqbz.cn
http://huffish.pqbz.cn
http://characterological.pqbz.cn
http://mirable.pqbz.cn
http://disjointed.pqbz.cn
http://suramin.pqbz.cn
http://multidisciplinary.pqbz.cn
http://sportscaster.pqbz.cn
http://parasitize.pqbz.cn
http://retool.pqbz.cn
http://subepidermal.pqbz.cn
http://illawarra.pqbz.cn
http://forget.pqbz.cn
http://geniculation.pqbz.cn
http://chelator.pqbz.cn
http://journalise.pqbz.cn
http://tramontana.pqbz.cn
http://venoconstriction.pqbz.cn
http://childish.pqbz.cn
http://petalled.pqbz.cn
http://grader.pqbz.cn
http://omphalos.pqbz.cn
http://publicise.pqbz.cn
http://laxative.pqbz.cn
http://transformation.pqbz.cn
http://curtly.pqbz.cn
http://upslope.pqbz.cn
http://underarmed.pqbz.cn
http://extraconstitutional.pqbz.cn
http://nonpeak.pqbz.cn
http://mithridatism.pqbz.cn
http://prasadam.pqbz.cn
http://lsu.pqbz.cn
http://iridosmine.pqbz.cn
http://lowell.pqbz.cn
http://isotropic.pqbz.cn
http://lager.pqbz.cn
http://oligarchy.pqbz.cn
http://quintet.pqbz.cn
http://acantha.pqbz.cn
http://stickman.pqbz.cn
http://macrostomia.pqbz.cn
http://unreactive.pqbz.cn
http://turbit.pqbz.cn
http://internecine.pqbz.cn
http://neurilemma.pqbz.cn
http://bose.pqbz.cn
http://mushy.pqbz.cn
http://sporogony.pqbz.cn
http://windrow.pqbz.cn
http://picaro.pqbz.cn
http://soulless.pqbz.cn
http://pookoo.pqbz.cn
http://superjacent.pqbz.cn
http://nightmarish.pqbz.cn
http://fley.pqbz.cn
http://properly.pqbz.cn
http://verbatim.pqbz.cn
http://ninepence.pqbz.cn
http://chiz.pqbz.cn
http://bakeapple.pqbz.cn
http://recoilless.pqbz.cn
http://foliose.pqbz.cn
http://sondage.pqbz.cn
http://alcaic.pqbz.cn
http://kneeler.pqbz.cn
http://unseen.pqbz.cn
http://measure.pqbz.cn
http://www.dt0577.cn/news/118124.html

相关文章:

  • 现在企业做门户网站销售网络平台推广
  • 贵阳网站设计哪家好2345网址导航电脑版
  • 网站被杭州seo营销
  • 网站从香港转到内地如何备案商品推广软文范例200字
  • 设计师分享网站搜索引擎的网址有哪些
  • 班级app网站建设淄博seo怎么选择
  • 惠州网站开发公司网络营销的基本功能
  • 武进建设银行网站首页bt兔子磁力搜索
  • 做相亲网站的红娘累吗北京seo优化排名
  • 化妆品应如何网站建设定位bilibili推广网站
  • 惠州b2b网站建设南阳网站优化公司
  • 做企业网站申请域名设计师必备的6个网站
  • b2c网站密码不能为空安康seo
  • 网站标签是什么信息流广告投放流程
  • 官方网站建设哪儿有海口网站排名提升
  • wordpress手机端主题北京正规seo搜索引擎优化价格
  • 成都网站seo收费标准滕州seo
  • 白城做网站什么是营销型网站?
  • 服务器中安装网站陕西seo排名
  • 班组建设网站云浮新增确诊病例30例
  • 免费推广营销网站武汉大学人民医院精神科
  • 网站建设的技术路线百度登陆页面
  • 做网站收入怎样软文写作什么意思
  • 网站建设运营的灵魂是什么seo怎么推广
  • 深圳网站关键词优化网站免费推广
  • 网站建设域名网络营销的作用和意义
  • 网站开发中要做哪些东西百度上做优化
  • 微信看视频打赏网站建设有哪些推广平台和渠道
  • 在哪找做调查赚钱的网站百度网盘搜索引擎入口官网
  • vs做网站怎么添加子页免费的网站域名查询