我不知道这里发生了什么事。我在一个单独的JVM中启动一个RMI服务器。在连接到调用远程方法的实例时,该方法在很短的时间内就会被卡住。一旦我关闭客户端进程,执行就会继续。
我做错了什么?
class Client
...
//name some kind of name
String name= "HelloService";
//libname points to a runnable jar with the server class as main class
ProcessBuilder jvm= new ProcessBuilder(javaPath, "-jar", libname, "-n", name);
jvm.start();
//Waiting for RMI server to start
try { Thread.sleep(10000); } catch ...
try {
Registry registry= LocateRegistry.getRegistry(1199);
//String as input and String as output
IRemoteService<String, String> service= (IRemoteService<String, String>) registry.lookup(name)
String returnVal= service.execute("SomeValue");
return returnVal;
} catch ...后面是服务器代码片段。服务器代码以MainClass的形式打包在一个可运行的jar中。
class Server implements IRemoteService<String, String>
//Is not returning a value, due the fact that I liked to examine the behaviour of
//this method. Doing this by running an infinite loop.
public String execute(String str) {
log.info("Running doExectue from "+getClass().getSimpleName());
int i=0;
while(true) {
i++;
log.info(String.valueOf(i));
}
}
protected static void register(String name, IRemoteService service) {
try {
IRemoteService rsStub= (IRemoteService) UnicastRemoteObject.exportObject(service,0);
Registry registry= LocateRegistry.getRegistry(1199);
try {
registry.bind(name, rsStub);
} catch (ConnectException ce) {
registry= LocateRegistry.createRegistry(1199);
registry.bind(name, rsStub);
}
} catch ...
}
public static void main(String[] args) {
String rmiName= args[1];
IRemoteService<String, String> service= (IRemoteService<String, String>) new Server();
register(rmiName, service);
}现在,如果我启动客户机,日志文件将在方法"execute“中显示36次循环运行。而不是停下来。也没有其他客户端获取此对象或调用此方法。
一旦我杀死了客户端进程,它就会再次启动,并将永远运行。
对我来说,客户端似乎阻止了远程服务器方法的执行。但我不知道如何克服这种局面。
谢谢你提前提供帮助,
丹尼
发布于 2014-05-26 06:23:00
多谢你们的支持。您是对的,RMI客户端不能阻止服务器。所以我真的很困惑。但我发现了失败。
关于这个过程的是写到控制台。一旦缓冲区满了,进程就会停下来等待有人收集输出。
在我从日志配置中删除ConsoleAppender之后,作业将按预期运行。
发布于 2014-05-23 12:00:22
你所说的是不可能的。当服务器执行远程方法时,客户端不能阻止服务器。再找个解释。
https://stackoverflow.com/questions/23826552
复制相似问题