Why does log4j disable stack trace after (lots of) repetition of the same exception?
java, log4j, stack-trace
Solution
Using Java 5 or better?
Then you're seeing:
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`
Courtesy of the Java 5 release notes.
Problem
At one of our customer installations we had thousands of occurrences of the same exception. After a lot of well logged stacktraces (9332) the occurrence of the exception is still logged, but without stacktrace. After restarting the java process, the same thing: This time we had 17858 stacktraces and then only the exception occurrence itself. There is a similar question here, but no answer... Is it a log4j feature or bug? (I believe in the former, because I really like, what those apache guys do) Any ideas?