On Linux, the default was VFORK before Java 13. Support for POSIX_SPAWN on Linux was added in Java 12, then made the default in Java 13. On other Unix platforms (macOS, BSD, Solaris, AIX), POSIX_SPAWN was already the default before Java 12.
The jdk.lang.Process.launchMechanism system property applies to the java.lang.ProcessBuilder and Runtime.getRuntime().exec() implementation on Unix-like platforms (Linux, macOS, BSD, Solaris, AIX). The set of accepted values varies by platform: VFORK is only supported on Linux.
POSIX_SPAWN - Uses posix_spawn(3) to start a tiny helper program called jspawnhelper in a subprocess. Next, jspawnhelper reads the command data from the parent Java process over a Unix pipe. Lastly, it executes the command via execvp(3).FORK - Uses the standard POSIX fork(2) and exec system calls.VFORK - Uses the vfork(2) system call, Linux only. Faster than fork, but more dangerous because it borrows the parent process's memory space temporarily.Here are some other Java system properties:
com.sun.jndi.ldap.object.trustSerialDatajava.locale.providersjava.security.propertiesjdk.jar.maxSignatureFileSizejdk.lang.Process.allowAmbiguousCommandsjdk.nio.zipfs.allowDotZipEntryjdk.serialFilterjspawnhelper has read all the expected data from the pipe, jspawnhelper will block indefinitely on the reading end of the pipeJava has supported the jdk.lang.Process.launchMechanism system property since 12.
jdk.lang.Process.launchMechanism on StartupYou can set the jdk.lang.Process.launchMechanism java system property during startup of the java runtime using the -D command line argument:
java -Djdk.lang.Process.launchMechanism=POSIX_SPAWN MyAppMain
You may also be able to specify jdk.lang.Process.launchMechanism via the JAVA_TOOL_OPTIONS environment variable:
JAVA_TOOL_OPTIONS=-Djdk.lang.Process.launchMechanism=POSIX_SPAWN
jdk.lang.Process.launchMechanism at RuntimeYou can set jdk.lang.Process.launchMechanism at runtime with the following Java code:
System.setProperty("jdk.lang.Process.launchMechanism", "POSIX_SPAWN");
WARNING: Depending on the property and JVM version using
setPropertymay or may not work if the JDK Java class that uses this variable has already been loaded. The value of the jdk.lang.Process.launchMechanism system property may be cached within an internal private static variable of the implementing class.
To read the value of jdk.lang.Process.launchMechanism at runtime, you can use this Java code:
String propertyValue = System.getProperty("jdk.lang.Process.launchMechanism");
if (propertyValue != null) {
System.out.println("jdk.lang.Process.launchMechanism = " + propertyValue);
} else {
System.out.println("jdk.lang.Process.launchMechanism was null");
}