失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 【JVM 2 最经典的HashMap图文详解

【JVM 2 最经典的HashMap图文详解

时间:2020-05-26 10:18:58

相关推荐

【JVM 2 最经典的HashMap图文详解

GC在 HotSpot VM 5.0里有四种:

~incremental (sometimes called train) low pause collector~已被废弃,不在介绍

注:

throughput collector与concurrent low pause collector的区别是throughput collector只在young area使用使用多线程,而concurrent low pause collector则在tenured generation也使用多线程。

根据官方文档,他们俩个需要在多CPU的情况下,才能发挥作用。在一个CPU的情况下,会不如默认的serial collector,因为线程管理需要耗费CPU资源。而在两个CPU的情况下,也提高不大。只是在更多CPU的情况下,才会有所提高。当然 concurrent low pause collector有一种模式可以在CPU较少的机器上,提供尽可能少的停顿的模式,见CMS GC Incremental mode

当要使用throughput collector时,在java opt里加上-XX:+UseParallelGC,启动throughput collector收集。也可加上-XX:ParallelGCThreads=来改变线程数。还有两个参数 -XX:MaxGCPauseMillis=和 -XX:GCTimeRatio=,MaxGCPauseMillis=用来控制最大暂停时间,而-XX: GCTimeRatio可以提高GC说占CPU的比,以最大话的减小heap。

二、CMS GC Incremental mode

=============================

当要使用 concurrent low pause collector时,在java的opt里加上 -XX:+UseConcMarkSweepGC。concurrent low pause collector还有一种为CPU少的机器准备的模式,叫Incremental mode。这种模式使用一个CPU来在程序运行的过程中GC,只用很少的时间暂停程序,检查对象存活。

在Incremental mode里,每个收集过程中,会暂停两次,第二次略长。第一次用来,简单从root查询存活对象。第二次用来,详细检查存活对象。整个过程如下:

* stop all application threads; do the initial mark; resume all application threads(第一次暂停,初始话标记)* do the concurrent mark (uses one procesor for the concurrent work)(运行是标记)* do the concurrent pre-clean (uses one processor for the concurrent work)(准备清理)* stop all application threads; do the remark; resume all application threads(第二次暂停,标记,检查)* do the concurrent sweep (uses one processor for the concurrent work)(运行过程中清理)* do the concurrent reset (uses one processor for the concurrent work)(复原)

当要使用Incremental mode时,需要使用以下几个变量:

-XX:+CMSIncrementalMode default: disabled 启动i-CMS模式(must with -XX:+UseConcMarkSweepGC)-XX:+CMSIncrementalPacing default: disabled 提供自动校正功能-XX:CMSIncrementalDutyCycle=<N> default: 50 启动CMS的上线-XX:CMSIncrementalDutyCycleMin=<N> default: 10 启动CMS的下线-XX:CMSIncrementalSafetyFactor=<N> default: 10 用来计算循环次数-XX:CMSIncrementalOffset=<N> default: 0 最小循环次数(This is the percentage (0-100) by which the incremental mode duty cycle is shifted to the right within the period between minor collections.)-XX:CMSExpAvgFactor=<N> default: 25 提供一个指导收集数

SUN推荐的使用参数是:

-XX:+UseConcMarkSweepGC \-XX:+CMSIncrementalMode \-XX:+CMSIncrementalPacing \-XX:CMSIncrementalDutyCycleMin=0 \-XX:CMSIncrementalDutyCycle=10 \-XX:+PrintGC Details \-XX:+PrintGCTimeStamps \-XX:-TraceClassUnloading# 本次面试答案,以及收集到的大厂必问面试题分享:![字节跳动超高难度三面java程序员面经,大厂的面试都这么变态吗?](https://img-/img_convert/8c936ac58ee51e214c00ca47a126b0a3.png)s \-XX:-TraceClassUnloading# 本次面试答案,以及收集到的大厂必问面试题分享:[外链图片转存中...(img-q0O7tWiC-1628507627209)]**[资料领取方式:戳这里即可免费下载](/vip204888/java-p7)**

如果觉得《【JVM 2 最经典的HashMap图文详解》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。