我找到了一种从任何进程关闭注册表的方法(为此,关闭注册表中绑定的任何绑定进程)
任何扩展远程并且您最终想要终止的接口也应该扩展以下接口:
public interface PIDSupplierInterface extends Remote {
String getPID() throws RemoteException;
}
然后,您创建的每个服务器类都必须实现 getPID() 作为其接口的一部分。然后您要做的就是返回进程 ID。适用于 Windows 的谷歌“getpids”,或访问此处:www.jroller.com/santhosh/entry/get_current_java_process_id。据我了解,对于 Linux,获取 PID 更简单。然后(在 Windows 中)你想去
String PID = myServer.getPID();
String[] a_command = { "taskkill", "/pid", PID };
Runtime.getRuntime().exec(a_command, envp, dir);
要杀死注册表本身的 PID,首先,在启动注册表时(以编程方式),只需执行
PIDSupplierInterface stub = PIDSupplierInterface)UnicastRemoteObject.exportObject(
new PIDSupplierServer(), 0);
reg.bind( "regKiller", stub );
其中 PIDSupplierServer 是一个仅实现 PIDSupplierInterface 的类。
然后,当您想从任何进程中终止 RMI 注册表时,只需执行
PIDSupplierInterface regProcess = (PIDSupplierInterface)reg.lookup( "regKiller" );
String regPID = regProcess.getPID();
String[] a_command = { "taskkill", "/pid", regPID };
Runtime.getRuntime().exec(a_command, envp, dir);
reg 已从您的系统中消失。还是由于某种原因您的问题更复杂?欢迎任何意见。