我正在学习Java Process,并且试图创建在同一进程中运行的同一java类的两个实例。
class Chat {
public void getMessage() { * * * some implementation
}
}
class ProcessMain {
public static void main(String args[]) {
Chat c1 = new Chat();
Chat c2 = new Chat();
ProcessBuilder pb = new ProcessBuilder(c1); * * * * here is where I am stuck.
Two instances of same class should run in same process
}
}
谁能给我带头?
答案 0 :(得分:0)
默认情况下,Java将在同一thread上的单个进程中运行主类。如果要让两个类相互通信,则可以传递c1 into a method inside of c2并以这种方式更改c1。