5.JVM三大效能調優引數:-Xms -Xmx -Xss
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));
}
}
}