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

1...-Xss是对每个线程stack大小的调整。直接影响对方法的调用次数

测试结果:

配置:

 



/**
 * Created by GK_LZS  ON 2019/4/17
 */
public class HelloStackOverFlow {
    private static int counter;

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

    }

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

    }


}

 

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

-Xms初始堆大小

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

配置:

/**
 * Created by GK_LZS  ON 2019/4/17
 */

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

 


版权声明:本文为qq_39507276原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。