从实际案例聊聊Java应用的GC优化
https://tech.meituan.com/2017/12/29/jvm-optimize.html
JVM介绍
https://juejin.im/post/5e1505d0f265da5d5d744050
Java打印异常堆栈优化
https://blog.csdn.net/tengdazhang770960436/article/details/91838820
JVM 默认添加了-XX:+OmitStackTraceInFastThrow
参数,遇到大量相同异常堆栈时便不再打印
去掉JVM的优化:-XX:-OmitStackTraceInFastThrow
public class TestStackTrace {
public static void main(String[] args) {
int i = 0;
String x = null;
while (i < 30000) {
try {
System.out.println("当前执行次数为:" + i);
getNPE(x);
} catch (Exception e) {
int lth = e.getStackTrace().length;
System.out.println("length:" + lth);
e.printStackTrace();
if (lth == 0) {
return;
}
}
i++;
}
}
private static void getNPE(String x) {
System.out.println("当前字母为:" + x.toString());
}
}
默认开启优化时:
执行到 5547 次便不再打印堆栈
image.png
关闭默认优化时:
image.png
网友评论