Skip to content

Printing to the Standard Output Doesn’t Work from a JVM Shutdown Hook #849

Open
@asif-anwar

Description

@asif-anwar

Affected version

3.5.3

Bug description

Hi,
I have this simple JVM shutdown hook,

public class JVMShutdownHook {

    static {
        Thread hook = new Thread(() -> {
            System.out.println("***********************Sysout from JVMShutdownHook***********************");
        });
        System.out.println("Register JVM Hook");
        Runtime.getRuntime().addShutdownHook(hook);
    }
}

It's registered in the @BeforeAll method

public class JVMHookApplicationTests {

    @BeforeAll
    public static final void initiateJVMHook() throws ClassNotFoundException {
        Class.forName("com.example.jvmHook.JVMShutdownHook");
    }

    @Test
    public void simpleTest() {
        assertEquals(6, 6);
    }
}

The sysout from the JVM hook doesn't work if the forkCount is greater than 0. The JVM hook gets called consistently, but printing to the standard output doesn't always work (it works sometimes, but the behaviour is inconsistent).

The problem started from Suefire version 3.0.0-M5. It works fine with 3.0.0-M4 and prior versions.

Here is a simple application showing this problem - https://github.com/asif-anwar/jvm-hook

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions