实例演示MaxTenuringThreshold参数及阈值动态调整策略
对Survivor空间来说:
当某一个Survivor空间中对象所占据的空间容量超过了60%,将会重新计算对象晋升的阈值,
而不会使用MaxTenuringThreshold所显示配置的阈值。如:survivor空间为10M是,那么当
对象占用6M时,就会重新计算对象晋升的阈值。
-XX:TargetSurvivorRatio=60
-XX:PrintGCDateStamps 打印当前GC的时间戳
-XX:+UseConcMarkSweepGC CMS垃圾回收器,在老年代中使用
-XX:UseParNewGC Serial的多线程收集器,在新生代中使用
实例:
-verbose:gc
-Xms200M
-Xmn50M
-XX:TargetSurvivorRatio=60
-XX:+PrintTenuringDistribution
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:MaxTenuringThreshold=3
public class MyTest4 {
public static void main(String[] args) throws InterruptedException {
byte[] byte_1 = new byte[512 * 1024];
byte[] byte_2 = new byte[512 * 1024];
myGc();
Thread.sleep(1000);
System.out.println("111111");
myGc();
Thread.sleep(1000);
System.out.println("222222");
myGc();
Thread.sleep(1000);
System.out.println("333333");
myGc();
Thread.sleep(1000);
System.out.println("444444");
byte[] byte_3 = new byte[1024 * 1024];
byte[] byte_4 = new byte[1024 * 1024];
byte[] byte_5 = new byte[1024 * 1024];
myGc();
Thread.sleep(1000);
System.out.println("555555");
myGc();
Thread.sleep(1000);
System.out.println("666666");
System.out.println("hello world");
}
private static void myGc(){
for (int i = 0; i < 40; i++) {
byte[] byteArray = new byte[1024*1024];
}
}
}