我遇到了一种奇怪的情况,在LogManager.getLogger stalls Application for ~10-30 Seconds when using JDK8:中也有类似的描述,但没有提出解决方案。Log4j使用LogManager.getLogger和getContext缓慢初始化()
的事情是,该记录器通过
final Logger logger = LogManager.getLogger(MyClass.class.getSimpleName());
初始化摊位我申请了近7秒(在最新的MacBook Pro 15" 2017)IF如果有任何的WiFi禁用,或者如果我拴在我的iPhone 但是,如果我通过WiFi(无共享)连接了可用的Internet连接,则log4j初始化将在1.5秒内运行 这是一个非常奇怪的行为。首先,我认为log4j尝试访问互联网和几秒钟后超时,但后来又一次:为什么当我共享,因此有权访问互联网的相同行为?
当进一步调试,我发现这个方法,只要服用:
public static LoggerContext getContext(final boolean currentContext) {
// TODO: would it be a terrible idea to try and find the caller ClassLoader here?
try {
return factory.getContext(FQCN, null, null, currentContext, null, null);
} catch (final IllegalStateException ex) {
LOGGER.warn(ex.getMessage() + " Using SimpleLogger");
return new SimpleLoggerContextFactory().getContext(FQCN, null, null, currentContext, null, null);
}
}
尤其是这样的:
factory.getContext(FQCN, null, null, currentContext, null, null);
有没有人有一个线索,为什么发生这种情况,我该如何解决这一问题?
这不提供问题的答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/17438117) – Olly