admin管理员组文章数量:1400744
I find these codes in our old project. It appears to filter the classes generated by reflections in the exception stack before printing the log. But I debugged this method and found that it does not load classes in the exception's stack.(Version: Java21 and Log4j2 2.17.1) So is these codes necessary to prevent the thread block which caused by class loading.
log.error("query failed", ExceptionUtil.filterReflectTrace(e));
/**
* Filtering reflection related classes, after JVM reflection optimization, log4j output exception stack will block threads due to repeated loading of these classes, especially GeneratedMethodAccessor
* @param e
* @return
*/
public static Throwable filterReflectTrace(Throwable e) {
if (!(e instanceof InvocationTargetException)) {
return e;
}
Throwable cause = e.getCause() == null ? e : e.getCause();
StackTraceElement[] traces = cause.getStackTrace();
List<StackTraceElement> list = new ArrayList<>();
for (StackTraceElement element : traces) {
String className = element.getClassName();
if (className.contains("GeneratedMethodAccessor") || className.contains("DelegatingMethodAccessorImpl")
|| className.contains("NativeMethodAccessorImpl")) {
continue;
}
list.add(element);
}
StackTraceElement[] newTraces = new StackTraceElement[list.size()];
cause.setStackTrace(list.toArray(newTraces));
return cause;
}
- I debugged this method and found that it does not load classes in the exception's stack.
- I find this website: . It seems this issue had no progress.(I'm not sure)
本文标签: javaWill log4j2 still trigger class loading when printing the thread stackStack Overflow
版权声明:本文标题:java - Will log4j2 still trigger class loading when printing the thread stack? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744280754a2598638.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论