A java library to run pieces of code in another (new) JVM.
- Limit code execution memory (-Xmx??).
- Safe native code execution (Main JVM not killed by DLL/SO/DYLIB invalid address error).
- Prevent external code to manipulate your objects.
- Run limited one-per-jvm code (singleton) in parallel.
- In use with external binaries can limit cpu usage too.
For single sync execution:
// Specify JVM options (optional)OneRunOutProcessoneRun = newOneRunOutProcess("-Xmx32m");
// Run in JVM 1 and exitintreturnCode = oneRun.run(() -> System.out.println("Hello 1"));
// Call in JVM 2 and exitSystem.out.println(oneRun.call(() -> System.getProperty("java.version")).getResult());For consecutive/async executions:
// Specify JVM options (optional)OutProcessExecutorServicesharedProcess = newOutProcessExecutorService("-Xmx32m");
// Submit a task to run in external JVMsharedProcess.submit(newCallableSerializable<String>() {
@OverridepublicStringcall() {
returnSystem.setProperty("SHARED_DATA", "EXECUTED");
}
});
// Get shared data in external JVM and wait (.get())Stringvalue = sharedProcess.submit(newCallableSerializable<String>() {
@OverridepublicStringcall() {
returnSystem.getProperty("SHARED_DATA");
}
}).get();
System.out.println(value);<dependency>
<groupId>com.github.dyorgio.runtime</groupId>
<artifactId>out-process</artifactId>
<version>1.2.7</version>
</dependency>