您的位置:首页 > 其它

5.JVM三大性能调优参数:-Xms -Xmx -Xss

2016-05-31 11:37 381 查看
1.-Xss是对每个线程stack大小的调整。直接影响对方法的调用次数

测试结果:









测试代码:

package com.dt.spark.jvm.basics;

public class HelloStackOverFlow {
private static int counter;

  

    public void count() {

       System.out.println("the stack frame depth is : "+(++counter));

       count();

    }

public static void main(String[] args) {
//-verbose:gc -Xms10M -Xmx10M -Xss105k -XX:+PrintGCDetails
System.out.println("HelloStackOverFlow");
HelloStackOverFlow helloStackOverFlow = new HelloStackOverFlow();
try {
helloStackOverFlow.count();
} catch (Exception e) {
System.out.println("the stack frame depth is : "+(++counter));
e.printStackTrace();
throw e;
}

}

}

2.-Xms -Xmx 是对heap的调整

-Xms初始堆大小

-Xmx最大堆大小,一般情况下这两个值设为相同大小。因为如果不相同且内存不够用时会发生内存抖动现象,非常影响程序运行。

测试结果:








测试代码:

package com.dt.spark.jvm.basics;

import java.util.ArrayList;

import java.util.List;

class Person{ }

public class HelloHeapOutOfMemory {

public static void main(String[] args) {
System.out.println("HelloHeapOutOfMemory");
List<Person> persons = new ArrayList<Person>();
int counter = 0;
      while(true){
      persons.add(new Person());
      System.out.println("Instance: " + (++counter));
      }

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: