java - 如何让 Java RMI 进程不终止
问题描述
节点.java:
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.io.Serializable;
public class Node implements NodeInterface,Serializable {
public Node(String URL) throws RemoteException {
try {
if (!(URL.equals("0"))) {
NodeInterface nodeinterface;
nodeinterface = (NodeInterface) Naming.lookup("0");
nodeinterface.join("0");
}
}
catch(Exception e) {
System.out.println(String.format("Encountering issues while constructing the server class. Error %s%n", e.getMessage()));
}
}
public boolean join (String nodeURL) throws RemoteException {
synchronized (this) {
try {
System.out.println("printing from inside node 0");
return true;
}
catch(Exception e) {
throw new RemoteException(String.format("Error %s", e.getMessage()));
}
}
}
public static void main(String[] args) {
try {
Node node = new Node(args[0]);
Naming.rebind(args[0],node);
//System.out.println
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
节点接口.java:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface NodeInterface extends Remote {
public boolean join (String nodeURL) throws RemoteException;
}
当我编译此代码并执行java Node 0
时,进程终止并执行java Node 1
产生输出printing from inside node 0
。
我希望看到这项工作如下:在终端 1:
Java Node 0
然后,在 2 号航站楼:
Java Node 1
然后我希望在 1 号航站楼看到:
printing from inside node 0
为了使这成为可能,我必须对我的代码进行哪些更改?
解决方案
推荐阅读
- python - 合并文本分类的多种统计方法,从 SVM 多类分类器开始
- asp.net-mvc - MVC:Ajax.ActionLink 是否可以使用图像和图像右侧的文本?
- vba - 如何在代码中将数组函数与数组一起使用
- java - 获取 java.io.IOException:服务器返回 HTTP 响应代码:400
- copy-paste - MobaXterm 鼠标右键双击
- r - 使用 rvest 从 ballotpedia.org 抓取表格数据
- c# - 在执行 select 子句之前检查列是否存在
- java - 扩展 JFrame 创建新的 JFrame 对象
- javascript - 在本机反应中使用 map() 列出数组元素
- jquery - 代表面板标题单击到引导手风琴的内部链接