Restarting a Java program does not work with the new JDK 21.02_13

169 Views Asked by At

my Java app experienced a very weird regression when switching from JDK OpenJDK21U-jdk_x64_windows_hotspot_21.0.1_12 to OpenJDK21U-jdk_x64_windows_hotspot_21.0.2_13

This small snippet should start a third party software (in this case Notepad++.exe but it's just an example) and after 30 seconds, close the java app that launched it.

public static void main(String... args) throws IOException {
        String[] cmdToRunUsingArgs = {"cmd.exe", "/C", "C:\\Program Files\\Notepad++\\notepad++.exe"};
        Runtime.getRuntime().exec(cmdToRunUsingArgs);
        Executors.newSingleThreadScheduledExecutor().schedule(() -> {
            System.exit(0);
        }, 30, TimeUnit.SECONDS);
    }

It works well with all previous JDK versions but it stopped working from java 21.0.2 and later.

With JDK 21.0.1, the program launches the third party app correcly, after 30 seconds, it kills itself by leaving the third app running.
With JDK 21.0.2, the program launches the third party app correcly, after 30 seconds, it kills itself AND the third party app.

this makes even impossible to restart a java app from the app itself.

The problems happens if you create the exe file with JPackage and then you launch the program using the exe file,
if you run the jar file with java -jar does not occur.

Any idea why the new JDK introduced this regression?

Expected Results

Program should start the third party app and then close itself after 30 seconds by leaving the third party app running.

Actual Results

Program start the third party app but after 30 seconds it kills both the third party app and itself.

0

There are 0 best solutions below