
获得徽章 0
- 详情:
yoshihisaonoue.wordpress.com
今天日志系统发现异常日志无堆栈信息,发现 jvm 对于一些异常 如NullPointerException、ArithmeticException 在多次重复抛出之后,后续的抛出会省略堆栈。对应jvm配置:-XX:-OmitStackTraceInFastThrow
示例代码:
public class TestOmitStackTraceInFastThrow {
public static void main(String[] args) {
int counter = 0;
while(true) {
try {
Object obj = null;
/*
* If we cause the exception every time(= without this "if" statement), the optimization does not happen somehow.
* So, cause it conditionally.
*/
if(counter % 2 == 0) {
obj = new Object();
}
// Cause NullpointerException
obj.getClass();
}catch(NullPointerException e) {
e.printStackTrace();
}
counter++;
}
}
}展开评论点赞