Out Process

Build Status Maven Central

A java library to run pieces of code in another (new) JVM.

Why use it?

Usage

For single sync execution:

// Specify JVM options (optional)
OneRunOutProcess oneRun = new OneRunOutProcess("-Xmx32m");
// Run in JVM 1 and exit
int returnCode = oneRun.run(() -> System.out.println("Hello 1"));
// Call in JVM 2 and exit
System.out.println(oneRun.call(() -> System.getProperty("java.version")).getResult());

For consecutive/async executions:

// Specify JVM options (optional)
OutProcessExecutorService sharedProcess = new OutProcessExecutorService("-Xmx32m");
// Submit a task to run in external JVM
sharedProcess.submit(new CallableSerializable<String>() {
    @Override
    public String call() {
        return System.setProperty("SHARED_DATA", "EXECUTED");
    }
});
// Get shared data in external JVM and wait (.get())
String value = sharedProcess.submit(new CallableSerializable<String>() {
    @Override
    public String call() {
        return System.getProperty("SHARED_DATA");
    }
}).get();
System.out.println(value);

Maven

<dependency>
    <groupId>com.github.dyorgio.runtime</groupId>
    <artifactId>out-process</artifactId>
    <version>1.2.7</version>
</dependency>