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

来源:互联网 发布:java消息服务器怎么写 编辑:程序博客网 时间:2024/06/05 18:16

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));
      }


}


}

0 0