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

织梦 大型综合旅游网站 源码html怎么做

织梦 大型综合旅游网站 源码,html怎么做,网站导航栏固定,厦门网站建设厦门写在前面 本文看下Java的强#xff0c;软#xff0c;弱#xff0c;虚引用相关内容。 1#xff1a;各种引用介绍 顶层类是java.lang.ref.Reference,注意是一个抽象类#xff0c;而不是接口#xff0c;其中比较重要的引用队列ReferenceQueue就在该类中定义#xff0c;子…写在前面 本文看下Java的强软弱虚引用相关内容。 1各种引用介绍 顶层类是java.lang.ref.Reference,注意是一个抽象类而不是接口其中比较重要的引用队列ReferenceQueue就在该类中定义子类们共同使用 // java.lang.ref.Reference public abstract class ReferenceT {// ...volatile ReferenceQueue? super T queue;// ... }另以下测试案例使用的gc配置 -Xms10m -Xmx10m -XX:PrintGC1.1强引用 平时我们用的默认就是强引用。所以也就没有一个类似于StrongReference的类来代表强引用了。 1.2软引用 使用类SoftReference代表一个软引用比强引用稍微弱化些在内存空间充足时发生GC不会被回收但是在内存不足发生GC时将会被回收所以适合用在类似于缓存这种并不会对程序起到决定性作用的场景中。如下例子 public void softRefTest() {/**** author mikechen*/Object obj new Object();SoftReference softRef new SoftReferenceObject(obj);obj null;//删除强引用byte[] b new byte[1024 * 1024];System.gc();//调用gcSystem.out.println(gc之后的值 softRef.get()); // 对象依然存在 }运行 [GC (System.gc()) 2663K-1713K(9728K), 0.0011382 secs] [Full GC (System.gc()) 1713K-1647K(9728K), 0.0055792 secs] gc之后的值java.lang.Object330bedb4Process finished with exit code 0这里内存不足的场景我没有试出来要么就OOM了。 软引用也可以选择和ReferenceQueue来一起使用当软应用关联的对象被GC之后就会将软引用本身添加到队列中如下 public void softRefWithQueue() throws Exception {ReferenceQueueObject queue new ReferenceQueue();Object obj new Object();SoftReference softRef new SoftReferenceObject(obj, queue);//删除强引用obj null;//调用gcSystem.gc();System.out.println(gc之后的值: softRef.get()); // 对象依然存在,虽然GC但内存足够不会回收//申请较大内存使内存空间使用率达到阈值强迫gcbyte[] bytes new byte[1024 * 1024 * 6];//如果obj被回收则软引用会进入引用队列System.out.println(111);//调用gcSystem.gc();Reference? reference queue.remove(); // 因为没有触发内存不足的场景所以不会添加到队列中所以这里会卡着System.out.println(222);if (reference ! null) {System.out.println(对象已被回收: reference.get());// 对象为null} }运行 同样试不出来内存不足被回收的场景。 1.3弱引用 弱引用和软引用的区别是在发生GC时不管内存是否足够都会被回收看个例子 private void weakRef() {Object o1 new Object();WeakReferenceObject w1 new WeakReferenceObject(o1);// System.out.println(o1);System.out.println(w1.get()); // 因为此时还有强引用肯定不会被回收o1 null; // 手动去除强引用System.gc();// System.out.println(o1);System.out.println(因为发生了GC所以就被回收掉了:);System.out.println(w1.get()); // 因为发生了GC所以就被回收掉了 }运行 java.lang.Object330bedb4 [GC (System.gc()) 1570K-745K(9728K), 0.0010741 secs] [Full GC (System.gc()) 745K-622K(9728K), 0.0059361 secs] 因为发生了GC所以就被回收掉了: nullProcess finished with exit code 0当然也可以和ReferenceQueue一起使用来监听对象被回收的动作: private void weakRefWithQueueV1() throws Exception {CC o1 new CC();o1.setName(张三);ReferenceQueue referenceQueue new ReferenceQueue();MapWeakReference, String map new HashMap();WeakReferenceCC w1 new WeakReferenceCC(o1, referenceQueue);map.put(w1, w1.get().getName()); // System.out.println(w1); // // System.out.println(o1);System.out.println(w1.get()); // 因为此时还有强引用肯定不会被回收o1 null; // 手动去除强引用System.gc();// System.out.println(o1);System.out.println(因为发生了GC所以就被回收掉了:);System.out.println(w1.get()); // 因为发生了GC所以就被回收掉了final Reference ref referenceQueue.remove();System.out.println(map.get(ref) 被回收了); // 因为对象被回收所以弱引用对象本身会被放到队列中 }运行 org.example.Main$CC2503dbd3 [GC (System.gc()) 1647K-709K(9728K), 0.0009438 secs] [Full GC (System.gc()) 709K-628K(9728K), 0.0058506 secs] 因为发生了GC所以就被回收掉了: null 张三 被回收了Process finished with exit code 01.4虚引用 虚引用是最弱的的一种引用不决定对象的生命周期有跟没有一样即形同虚设必须和ReferenceQueue共同使用一般用来监控jvm的gc活动如下例子 private void weakPhantomWithQueueV1() throws Exception {CC o1 new CC();o1.setName(张三1);ReferenceQueue referenceQueue new ReferenceQueue();MapPhantomReference, String map new HashMap();PhantomReferenceCC w1 new PhantomReferenceCC(o1, referenceQueue);map.put(w1, o1.getName()); // System.out.println(w1);// System.out.println(o1);System.out.println(w1.get()); // 因为此时还有强引用肯定不会被回收o1 null; // 手动去除强引用System.gc();// System.out.println(o1);System.out.println(因为发生了GC所以就被回收掉了:);System.out.println(w1.get()); // 因为发生了GC所以就被回收掉了final Reference ref referenceQueue.remove();System.out.println(map.get(ref) 被回收了); // 因为对象被回收所以弱引用对象本身会被放到队列中 }运行 null [GC (System.gc()) 1643K-741K(9728K), 0.0012171 secs] [Full GC (System.gc()) 741K-627K(9728K), 0.0062680 secs] 因为发生了GC所以就被回收掉了: null 张三1 被回收了Process finished with exit code 02在框架中的应用 2.1在netty中的应用 just go。 2.2在mybatis中的应用 TODO 写在后面 参考文章列表 Java四大引用详解强引用、软引用、弱引用、虚引用 。 netty之内存泄露检测。
http://www.ho-use.cn/article/10816115.html

相关文章:

  • 烟台酒店网站建设品牌战略咨询公司排名
  • 邢台移动网站设计临沂外贸国际网站建设
  • 如何做网站维护 找关键词做旅游网站的研究意义
  • 简单网站开发准备做钢材都有什么网站
  • 免费的ppt模板网关键词优化是什么意思
  • 深圳外贸建站模版创意网站建设设计
  • 微网站样式网站建设后还有什么费用
  • 上海住房和城乡建设厅网站wordpress自带企业主题下载
  • 有人和兽做的网站移动端网站排名
  • 手机网站解析做网站的一般要多钱
  • wordpress 首页缩略图seo多久可以学会
  • 全景旅游网站项目建设淘宝网站代理怎么做的
  • 小红书seo是什么意思系统优化大师免费版
  • 静态网站管理系统wordpress display_name
  • 食品网站建设目的做网站软件wd
  • 站长工具域名wordpress转发微信缩略图
  • 网站群发手机短信国内搜索引擎排名2022
  • 阳泉网站建设南充市房地产网官方网站
  • 网站开发项目的心得体会电话销售哪里找客户电话
  • 国外包装设计网站大全wordpress网代码显示
  • 国外做婚纱的网站网站备案域名更改吗
  • 如何做产品网站网页设计南磨房网站建设公司
  • 宜家有做自己的网站吗wordpress注册填写密码错误
  • 怎么到国外网站去接模具订单做建设部网站监督平台
  • 开发网站开发工程师新人做外贸流程
  • 网站建设的两个方面wordpress如何调用插件
  • 合肥网站 技术支持 上诚科技企业门户网站框架设计
  • 怎么让织梦网站适合手机嘉兴网站制作公司
  • 移动开发和网站开发关键词优化网站
  • 免费云建站聊城网站营销信息