记一次日志打印异常堆栈缺失

记一次日志打印异常堆栈缺失

现象

线上监控告警收到一条告警日志信息,如下图,但是只有异常信息,查了很久也查不到打印的异常堆栈信息,

接口异常信息
java.lang.NullPointerException

查询代码,日志打印使用的logback ,本地启动,手动抛出异常,发现本地是会打印堆栈信息的

原因

查了资料,这里jvm在同一个方法抛出相同异常堆栈次数达到一定程度的时候,会使用JIT即时编译重新编译改方法,抛出一个不带堆栈的异常,所以没有打印堆栈信息,下面这些设定的异常才会

  • NullPointerException
  • ArithmeticException
  • ArrayIndexOutOfBoundsException
  • ArrayStoreException
  • ClassCastException

JIT即时编译

JIT is a part of the JVM that optimizes the performance of the application. JIT stands for Java-In-Time Compiler. The JIT compilation is also known as dynamic compilation. In this section, we will learn what is JIT in Java, its working, and the phases of the JIT compiler. What is JIT in Java? JIT in Java is an integral part of the JVM

简单说就是,将代码直接编译为机器指令代码,提高执行速度,

我们都知道java代码是险编译为class字节码文件,然后再通过jvm解释,生成机器指令的方式执行,而JIT就是跳过了jvm解释这一层

解决

  • 这段是官方说明,我们可以通过指定 -XX:-OmitStackTraceInFastThrow 参数来禁用此优化
The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions. For performance purposes, when such an exception is thrown a few times, the method may be recompiled. After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace. To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow
  • 已经出现的怎么找到异常堆栈?

    可以直接追溯此方法异常的最早出现的日志,里面是有堆栈信息打印的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值