LogManager.getLogger stops the application for ~ 10-30 seconds when using JDK8:

// UPDATE 1:

I did some more tests, removed most of the libs, and commented on the specific lib code, resulting in the same behavior, which robs me of the conclusion that this problem is not (directly) caused by these libs, but seems to be common in my code and / or at the construction site.

The main problem is that I don’t understand why it works fine when starting from eclipse (instant start, high performance, etc.), while the same code has the described problems as soon as I run it outside eclipse (like a runnable JAR using the same JDK!).

Can anyone shed light on what the differences might be?

// END OF UPDATE 1

// Original post:

based on the old question I asked here: Wrapped .exe with launch4j and jdk8 takes a lot of time. Using jdk7 instead starts almost instantly

Now I know that it is NOT related to launch4j with jdk8, but it seems to be called by log4j in combination with jdk8 in my application. Similar problems were discussed here: Log4j 2 freezes when creating a logger and here: log4j LogManager.getLogger get stuck in an infinite loop .

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

The main method of my application does some initialization before initializing the Logger object (for example, clearing old log files, etc.). Each step is printed for debugging purposes through System.out.println. Here is an 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 ( ), (< 1 ) :

MyTestCase...

1...

Init Stuff 2...

...

!

GUI...

runable JAR wrapped.exe( l4j) JDK JRE 8, , :

MyTestCase...

1...

Init Stuff 2...

...

/ ~ 10-45 < - !

!

GUI...

, JDK 7, "" , Eclipse. , , .

My buildpath/, :

CJWizards-0,22

--1,10

-IO-2,4

-lang3-3.4

- 1,2

-20.0

IText-2.1.7

JDatePicker-1.3.5

-4.3.0

- 4.3.0

log4j--2.8.1

log4j--2.8.1

sl4j--1.7.22

SLF4J-NOP-1.7.22

swingx--1.6.5-1

TableLayout

vlcj-3.10.1

zip4j_1.3.2

, ?

Recap:

  • , ( , jdk 7 8)

  • JDK JRE 7 runnable jar exe,

  • JDK JRE 8 exe

log4j2.xml, , :

<?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>
+5
1

- , "", JDK 9. , / JDK 8, JDK 9. "".

+1

Source: https://habr.com/ru/post/1672448/


All Articles