![JAR search and dependency download from the Maven repository](/logo.png)
org.objectfabric.SeparateVM Maven / Gradle / Ivy
/**
* This file is part of ObjectFabric (http://objectfabric.org).
*
* ObjectFabric is licensed under the Apache License, Version 2.0, the terms
* of which may be found at http://www.apache.org/licenses/LICENSE-2.0.html.
*
* Copyright ObjectFabric Inc.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.objectfabric;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Executes a Java application in a separate VM.
*/
class SeparateVM implements Separate {
public static final String PROGRESS_KEY = "__progress__";
private final Process _process;
private final Runnable _callback;
private volatile int _progressServer;
private static AtomicInteger _progressClient = new AtomicInteger();
private SeparateVM(Process process, Runnable callback) {
_process = process;
_callback = callback;
}
static SeparateVM start(String className, Collection args, Runnable callback) throws IOException {
ArrayList list = new ArrayList();
list.add(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
list.add("-cp");
list.add(System.getProperty("java.class.path"));
list.add("-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y");
list.add(SeparateVM.class.getName());
list.add(className);
list.addAll(args);
ProcessBuilder builder = new ProcessBuilder(list);
builder.directory(new File(System.getProperty("user.dir")));
builder.redirectErrorStream(true);
Process process = builder.start();
SeparateVM vm = new SeparateVM(process, callback);
vm.track();
return vm;
}
static void main(String[] args) throws Exception {
Class> c = Class.forName(args[0]);
ArrayList classes = new ArrayList();
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy