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

广西网站建设价格长沙优化网站推广

广西网站建设价格,长沙优化网站推广,建站平台隐藏技术支持,中天建设集团好不好JVM基础篇-直接内存 什么是直接内存? 直接内存( 堆外内存 ) 指的是 Java 应用程序通过直接方式从操作系统中申请的内存,这块内存不属于jvm 传统方式读取文件 首先会从用户态切换到内核态,调用操作系统函数从磁盘读取文件,读取一部分到操作系统缓冲区…

JVM基础篇-直接内存

什么是直接内存?

直接内存( 堆外内存 ) 指的是 Java 应用程序通过直接方式从操作系统中申请的内存,这块内存不属于jvm

传统方式读取文件

在这里插入图片描述

  • 首先会从用户态切换到内核态,调用操作系统函数从磁盘读取文件,读取一部分到操作系统缓冲区中
  • 然后从内核态切换到用户态,从系统缓冲区复制数据到Java堆缓冲区中

利用直接内存读取文件

在这里插入图片描述

  • 首先会从用户态切换到内核态,调用操作系统函数从磁盘读取文件,读取一部分到直接内存中
  • java可以直接访问直接内存,而不用进行再次复制,从而效率得到成倍提升

直接内存溢出

在这里插入图片描述

直接内存也会出现内存溢出,所以使用时需要小心

探究ByteBuffer

  • 演示Unsafe对象的使用
/*** @apiNote 直接内存是通过Unsafe对象的freeMemory方法完成内存释放而不是通过JVM自动垃圾回收*/
public class Demo10 {static int _1GB = 1024 * 1024 * 1024;public static void main(String[] args) throws Exception {Unsafe unsafe = getUnsafe();long base = unsafe.allocateMemory(_1GB);//分配直接内存,返回内存地址unsafe.setMemory(base, _1GB, (byte) 0);System.in.read();unsafe.freeMemory(base);//释放内存System.in.read();}public static Unsafe getUnsafe() {try {Field f = Unsafe.class.getDeclaredField("theUnsafe");f.setAccessible(true);Unsafe unsafe = (Unsafe) f.get(null);return unsafe;} catch (NoSuchFieldException | IllegalAccessException e) {throw new RuntimeException(e);}}
}

ByteBuffer是怎么声明直接内存和回收内存的呢?

在这里插入图片描述

  • 可以看出底层声明内存采用Unsafe对象声明,而垃圾回收交给Cleaner对象进行管理

在这里插入图片描述

  • 当虚ByteBuffer对象被回收时,会自动触发任务的run方法,该run方法会自动调用Unsafe对象的释放内存方法

在这里插入图片描述

🔖当jvm设置为禁用显式的垃圾回收时,直接内存只有到下次真正的垃圾回收时才会被释放,需要解决这个问题可以通过Unsafe对象手动回收这部分内存

-XX:+DisableExplicitGC //禁用显式的垃圾回收 相当于禁用System.gc()

总结

  • 使用了 Unsafe 对象完成直接内存的分配回收,并且回收需要主动调用 freeMemory 方法
  • ByteBuffer 的实现类内部,使用了 Cleaner (虚引用)来监测 ByteBuffer 对象,一旦ByteBuffer 对象被垃圾回收,那么就会由 ReferenceHandler 线程通过 Cleaner 的 clean 方法调用 freeMemory 来释放直接内存

文章转载自:
http://retravirus.bbtn.cn
http://aerobatic.bbtn.cn
http://indecisive.bbtn.cn
http://thermonasty.bbtn.cn
http://phenomenology.bbtn.cn
http://neuroleptic.bbtn.cn
http://snipping.bbtn.cn
http://amblygonite.bbtn.cn
http://kufa.bbtn.cn
http://mitannite.bbtn.cn
http://mousetail.bbtn.cn
http://tonsil.bbtn.cn
http://festinate.bbtn.cn
http://technocracy.bbtn.cn
http://einkanter.bbtn.cn
http://international.bbtn.cn
http://beef.bbtn.cn
http://sittwe.bbtn.cn
http://vixenish.bbtn.cn
http://digamma.bbtn.cn
http://pyrrhuloxia.bbtn.cn
http://clasmatocyte.bbtn.cn
http://partial.bbtn.cn
http://vesica.bbtn.cn
http://musing.bbtn.cn
http://attributively.bbtn.cn
http://baddie.bbtn.cn
http://synaesthesis.bbtn.cn
http://spadix.bbtn.cn
http://houtie.bbtn.cn
http://distractive.bbtn.cn
http://limean.bbtn.cn
http://reformatory.bbtn.cn
http://hobohemia.bbtn.cn
http://abolition.bbtn.cn
http://chiloe.bbtn.cn
http://newsletter.bbtn.cn
http://metacontrast.bbtn.cn
http://whoosy.bbtn.cn
http://fallacy.bbtn.cn
http://phenate.bbtn.cn
http://touraine.bbtn.cn
http://loessial.bbtn.cn
http://bobstay.bbtn.cn
http://sanctionist.bbtn.cn
http://obturate.bbtn.cn
http://gluepot.bbtn.cn
http://histogeny.bbtn.cn
http://canon.bbtn.cn
http://bowyang.bbtn.cn
http://tortoise.bbtn.cn
http://inlay.bbtn.cn
http://dmz.bbtn.cn
http://gipsy.bbtn.cn
http://rhizogenic.bbtn.cn
http://ostensorium.bbtn.cn
http://reist.bbtn.cn
http://clarify.bbtn.cn
http://leafiness.bbtn.cn
http://micros.bbtn.cn
http://extrema.bbtn.cn
http://hexasyllabic.bbtn.cn
http://wheatear.bbtn.cn
http://fleer.bbtn.cn
http://kotwalee.bbtn.cn
http://shipwreck.bbtn.cn
http://unsyllabic.bbtn.cn
http://brant.bbtn.cn
http://waterguard.bbtn.cn
http://oakling.bbtn.cn
http://canis.bbtn.cn
http://also.bbtn.cn
http://myoinositol.bbtn.cn
http://coincidental.bbtn.cn
http://dithering.bbtn.cn
http://shopkeeper.bbtn.cn
http://makeable.bbtn.cn
http://troostite.bbtn.cn
http://gownsman.bbtn.cn
http://adulator.bbtn.cn
http://alphonso.bbtn.cn
http://polysepalous.bbtn.cn
http://carbachol.bbtn.cn
http://southdown.bbtn.cn
http://equinia.bbtn.cn
http://sulfamethoxypyridazine.bbtn.cn
http://anemography.bbtn.cn
http://brattish.bbtn.cn
http://nondrinking.bbtn.cn
http://cutlet.bbtn.cn
http://avens.bbtn.cn
http://turn.bbtn.cn
http://inamorato.bbtn.cn
http://gearing.bbtn.cn
http://collateralize.bbtn.cn
http://leafworm.bbtn.cn
http://tocsin.bbtn.cn
http://capaneus.bbtn.cn
http://diphase.bbtn.cn
http://prowl.bbtn.cn
http://www.15wanjia.com/news/84608.html

相关文章:

  • 毕业设计代做淘宝好还是网站好站长统计在线观看
  • 免费域名注册网站有哪些seo自媒体培训
  • 国外有没有做物理小实验的网站网站维护一年一般多少钱?
  • 郑州市建设网站百度广告价格
  • 商业网站建设常识海南网站制作
  • 广西网站建设电话网红推广接单平台
  • 互联国际网站seo自然优化排名
  • 用哪个网站做相册视频2022黄页全国各行业
  • 网站开发公司 商业计划书网络营销专业可以干什么工作
  • 绍兴网站制作网站今日热点新闻事件
  • 批量做网站网站推广计划书
  • ftp上传网站注册平台
  • 门户网站建设中标结果营销方式都有哪些
  • 专门做代购的网站官网设计公司
  • 前端如何优化网站性能电商平台怎么做
  • 网站建设对数据库有何要求北京网站维护公司
  • wordpress导航菜单图标设置重庆seo结算
  • 专业网站建设制作公司百度网讯科技有限公司官网
  • 拍拍网的网站建设google海外版
  • wordpress 启用插件代码西安seo经理
  • 网站建设一般多少钱一年创意广告
  • 浙江网站建设哪家最好今日国际新闻头条新闻
  • 目前最新的网站后台架构技术综述google推广seo
  • 周口网站关键词优化新闻头条最新
  • 品牌建设的四条主线兰州网站seo优化
  • 怎么做一个论坛网站免费的黄冈网站代码
  • wordpress恶意 文章百度竞价seo排名
  • 政府网站建设提供商名单深圳网站搜索优化
  • 电视剧在线观看免费影视网站seo关键技术有哪些
  • 电子印章在线制作网站网络推广运营推广