使用JDK8时,LogManager.getLogger将应用程序停顿约10-30秒: [英] LogManager.getLogger stalls Application for ~10-30 Seconds when using JDK8:

查看:155
本文介绍了使用JDK8时,LogManager.getLogger将应用程序停顿约10-30秒:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//更新1:

我做了一些测试,删除了大部分的lib并注释掉了特定于lib的代码,导致了同样的行为让我得出结论,这个问题不是(直接)由这些库引起的,但似乎是我的代码和/或设置中的一般问题。

I did some more testing, removed most of the libs and commented out lib specific code resulting in the same behaviour which leeds me to the conclusion, that this problem is not (directly) caused by those libs but seems to be a general issue in my code and/or setup.

这里的主要问题是我不明白为什么它在eclipse(即时启动,高性能等)中启动时运行完美,而同样的代码在我在eclipse之外启动它时会有所描述的问题(作为可运行的JAR使用相同的JDK!)。

The main problem here is that I do not understand why it runs perfectly when launched from within eclipse (instant startup, high performance, etc) while the same code has the described problems as soon as i launch it outside of eclipse (as runnable JAR using the same JDK!).

有人可以了解可能存在的差异吗?

Can someone shed some light onto what differences there might be?

// END OF UPDATE 1

//原帖:

来自我在这里提出的一个较老的问题:使用launch4j和jdk8包装.exe需要很长时间才能启动。使用jdk7开始几乎立即开始

comming from an older question asked by me here: Wrapped .exe with launch4j and jdk8 takes very long to start. Using jdk7 instead starts almost instant

现在我知道它与使用jdk8的launch4j无关但它似乎是由log4j结合jdk8引起的我的应用程序。此处讨论了类似的问题: Log4j 2在创建记录器时挂起,此处:< A HREF = https://stackoverflow.com/questions/17838807/log4j-logmanager-getlogger-gets-stuck-in-an-infinite-loop> log4j的LogManager.getLogger得到的停留在一个无限循环。

Now i know that it is NOT related to launch4j with jdk8 but it seems to be caused by log4j in combination of jdk8 in my application. Similar problems were discusses here: Log4j 2 hangs when creating logger and here: log4j LogManager.getLogger get's stuck in an infinite loop.

但这些解决方案都不适合我。这个问题对我来说也有点不同。
我们走了:

But none of the solutions work for me. The problem is a little bit different for me, too. Here we go:

我的应用程序的主要方法是在初始化Logger对象之前执行一些初始化操作(比如清理旧的日志文件等) 。打印每个步骤以通过System.out.println进行调试。下面是一个简化示例:

The main Method of my application does some init stuff prior to initializing the Logger object (like cleaning up older log files, etc.). Each step is printed out for debugging purposes via System.out.println. Here is a reduced example:

public class MyTestCase {
    private static Logger logger; 

    public static void main(String[] args) throws Exception {
        System.out.println("Executing MyTestCase...");

        doInitstuff1();

        doInitstuff2();

        System.out.println("Initializing Logger...");    

        logger = LogManager.getLogger(MyTestCase.class.getName()); 

        System.out.println("Init complete!");

        doTheRealStuff();
    }

    private void doInitstuff1() {
        System.out.println("Init Stuff 1...");
    }

    private void doInitstuff2() {
        System.out.println("Init Stuff 2...");
    }

    private void doTheRealStuff() {
        System.out.println("Launching GUI...");
    }
}

当我从Eclipse中执行代码时(调试或运行配置没关系)immedeate输出(< 1秒开始和结束)是预期的:

When i execute the code from within Eclipse (debug or run configuration doesn't matter) the immedeate output (< 1 second to start and finish) is as expected:


执行MyTestCase .. 。

Executing MyTestCase...

Init Stuff 1 ...

Init Stuff 1...

Init Stuff 2 ...

Init Stuff 2...

初始化记录器......

Initializing Logger...

初始化完成!

启动GUI .. 。

当我创建一个可运行的JAR或一个包装的.exe(带有l4j)并执行安装了JDK或JRE 8的应用程序时在目标平台上,结果如下:

When I create a runable JAR or a wrapped .exe (with l4j) and execute the application with a JDK or JRE 8 installed on the target platform the result is this:


执行MyTestCase ...

Executing MyTestCase...

Init Stuff 1 ...

Init Stuff 1...

Init Stuff 2 ...

Init Stuff 2...

初始化记录器......

Initializing Logger...

应用程序挂起/停顿约10-45秒,具体取决于设备< - 这是实际问题!

Application hangs/stalls for ~10-45 seconds depending on the device <-- This is the actual problem!


初始化完成!

Init complete!

启动GUI ...

当我针对JDK 7编译完全相同的事情时,部署的可执行文件的启动速度与Eclipse内部一样快。这真的很奇怪,我不知道如何对付它。

When I do exactly the same thing compiled against JDK 7 the "deployed" executable launches as fast as from within Eclipse. This is really strange and i have no clue what to do against it.

我的构建路径/库用于测试目的&实验:

My buildpath / libraries used for testing purposes & experiments:


CJWizards-0.22

CJWizards-0.22

commons-codec-1.10

commons-codec-1.10

commons-io-2.4

commons-io-2.4

commons-lang3-3.4

commons-lang3-3.4

commons-logging-1.2

commons-logging-1.2

guava-20.0

guava-20.0

itext-2.1.7

itext-2.1.7

JDatePicker-1.3.5

JDatePicker-1.3.5

jna-4.3.0

jna-4.3.0

jna-platform-4.3.0

jna-platform-4.3.0

log4j-api-2.8.1

log4j-api-2.8.1

log4j-core-2.8。 1

log4j-core-2.8.1

sl4j-api-1.7.22

sl4j-api-1.7.22

slf4j-nop-1.7.22

slf4j-nop-1.7.22

swingx-all-1.6.5-1

swingx-all-1.6.5-1

tablelayout

tablelayout

vlcj-3.10.1

vlcj-3.10.1

zip4j_1.3.2

zip4j_1.3.2

任何想法是什么引起这个?

Any idea what is causing this?

回顾:


  • 从eclipse中运行问题没有发生(无论是否使用jdk 7或8)

  • running from within eclipse this problem does not occure (no matter if jdk 7 or 8 is used)

使用JDK或JRE 7作为runnable jar运行或执行问题em不会发生

running with JDK or JRE 7 as runnable jar or exe the problem does not occure

使用JDK或JRE 8作为runnable jar或exe运行时出现问题

running with JDK or JRE 8 as runnable jar or exe the problem occurs

这是我的log4j2.xml配置文件的内容,以防你需要它:

Here is the content of my log4j2.xml configuration file, just in case you need it, too:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="error">
    <appenders>
        <File name="MyTestCase.debug" fileName="${sys:user.home}/.mtc/log/MyTestCase.debug.log">
            <ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
            <PatternLayout pattern="%d{yyyy-MM-dd | HH:mm:ss.SSS} | [%t] %-5level | %logger{42}  | %msg%n"/>            
        </File>
                <Async name="Async.debug">
                    <appender-ref ref="MyTestCase.debug"/>
                </Async>        
        <File name="MyTestCase.error" fileName="${sys:user.home}/.mtc/log/MyTestCase.error.log">
            <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="%d{yyyy-MM-dd | HH:mm:ss.SSS} | [%t] %-5level | %logger{42}  | %msg%n"/>        
        </File>
                <Async name="Async.error">
                    <appender-ref ref="MyTestCase.error"/>
                </Async>
    </appenders>
    <loggers>       
        <root level="debug">                        
            <appender-ref ref="Async.debug" level="debug"/>
            <appender-ref ref="Async.error" level="error"/>
        </root>
    </loggers>
</configuration>


推荐答案

已经有一段时间了,但问题是解决了因为该项目已迁移到JDK 9.
我仍​​然不知道JDK 8导致这些问题的原因是什么,但是它们已经使用JDK 9消失了。所以我认为这个已经解决了。

It's been a while but the problem is "solved" since the project was migrated to JDK 9. I still don't know what was/is causing those issues with JDK 8 but they have disappeared using JDK 9. So i consider this "resolved".

这篇关于使用JDK8时,LogManager.getLogger将应用程序停顿约10-30秒:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆