获得徽章 0
赞了这篇沸点
做一个参与者,而不是旁观者,少浏览多输出,总是看技术的文章除了空耗时间外,对自己并不会有任何实质的成长,还会给自己一种认真学习的错觉,说到底看别人写的文章,本质是一种非常低效的学习,自己动手写才是王道。
评论
3
详情:
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++;
}
}
}
今天日志系统发现异常日志无堆栈信息,发现 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++;
}
}
}
展开
评论
点赞
![[捂脸]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_28.8981538.png)
![[吃瓜群众]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_10.42a731c.png)
![[流泪]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_6.dde0d83.png)