在我们的一个客户安装中,我们遇到了数千次相同的异常。在大量记录良好的堆栈跟踪 (9332) 之后,仍然记录了异常的发生,但没有堆栈跟踪。重新启动 java 进程后,同样的事情:这次我们有 17858 个堆栈跟踪,然后只有异常发生本身。
有个类似的问题here , 但没有答案...
这是 log4j 的特性还是错误? (我相信前者,因为我真的很喜欢那些 apache 家伙做的事)
有什么想法吗?
最佳答案
使用 Java 5 或更高版本?
然后你会看到:
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
由 Java 5 release notes 提供.
关于java - 为什么 log4j 在(多次)重复相同异常后禁用堆栈跟踪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1142007/