我发现从任何进程关闭注册表(为此事关停其在注册表中绑定任何绑定过程)
任何延伸远程和你最终想要的接口的方式杀死还应扩展以下接口:
public interface PIDSupplierInterface extends Remote {
String getPID() throws RemoteException;
}
你这个创建的每个服务器类作为其接口的一部分,必须然后实现GETPID()。那么你必须做的是返回进程ID。谷歌“getpids”的Windows,或去这里:www.jroller.com/santhosh/entry/get_current_java_process_id。据我所知,获得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已经从系统中消失了。或者由于某种原因你的问题更复杂?欢迎任何评论。
* * * * * * *可以导出* createRegistry()`。要确保它正在运行,请尝试`createRegistry()`:如果得到`BindException`,请调用`getRegistry()`。当然,你只能在前一种情况下出口,但在后一种情况下,它是其他人的注册局,因此他们有责任对其进行导出。 – EJP 2011-12-23 03:50:39