简体   繁体   English

Java RMI 连接断开

[英]Java RMI connection broken

We have an java client-server RMI application.我们有一个 java 客户端-服务器 RMI 应用程序。 The client performs a call by:客户端通过以下方式执行调用:

public interface MyRemoteInterface extends java.rmi.Remote {
    public byte[] action(byte[] b}

public static Remote lookUp(String ip, int port, String alias) {
    return LocateRegistry.getRegistry(ip, port).lookup(alias)
}


 serverImpl = (MyRemoteInterface)lookUp(ip, rmpiport, alias);

 serverImpl.action(requestBytes);
 ..

It a classic rmi client-server appl.它是一个经典的 rmi 客户端-服务器应用程序。 When the remote server receives the request (call) it performs some process P, which takes a time T and then returns.当远程服务器接收到请求(调用)时,它会执行一些过程 P,这需要时间 T 然后返回。 The problem is, suppose we have two clients C1 and C2, respectively, each are identical (same OS, same Java, no firewall, no antivirus etc).问题是,假设我们分别有两个客户端 C1 和 C2,每个客户端都是相同的(相同的操作系统,相同的 Java,没有防火墙,没有防病毒软件等)。 The difference of C1 and C2 is they are in different networks, different ISP provides etc. For example they are two users connecting from their home and use different service providers, modems and connecting to the centralized server S. When the process P takes 4 minutes, there is no problem, both client receive the response. C1和C2的区别在于他们在不同的网络,不同的ISP提供等。例如他们是两个用户从家里连接,使用不同的服务提供商,调制解调器并连接到集中式服务器S。当过程P需要4分钟时,没有问题,两个客户端都收到响应。 But if the process time takes for example 10 minutes, C2 receives no response without any exceptions on server or client side.但是如果处理时间需要例如 10 分钟,C2 在服务器或客户端没有任何异常都没有收到任何响应。 Question: What can be reason of this difference?问题:造成这种差异的原因是什么? How can the network architecture can effect the behaviour of rmi connection?网络架构如何影响 rmi 连接的行为? Can we overcome this problem by setting some timeout parameters or jvm-parameters?我们可以通过设置一些超时参数或jvm-parameters来克服这个问题吗? We do not get any timeout exceptions on client or server.我们没有在客户端或服务器上收到任何超时异常。 Simply one of the clients does not receive any response if the process time becomes longer.如果处理时间变长,那么其中一个客户端不会收到任何响应。

Simply one of the clients does not receive any response if the process time becomes longer.如果处理时间变长,那么其中一个客户端不会收到任何响应。

In our (enterprise) network we had some policy in force to close connections which were not active for long time.在我们的(企业)网络中,我们有一些有效的政策来关闭长时间不活跃的连接。 So there may be differences.所以可能会有差异。 Though the client should get a proper exception.虽然客户端应该得到一个适当的例外。 For better answer you may gather more exact information on the network level (eg tcpdump)为了获得更好的答案,您可以收集有关网络级别的更准确信息(例如 tcpdump)

But if the process time takes for example 10 minutes但是如果处理时间需要例如 10 分钟

I'm not really fond of long-running processes when executing remotely (regardless of the protocol).在远程执行时(不管协议如何),我不太喜欢长时间运行的进程。 Mainly to prevent issues like the one in your question.主要是为了防止出现您问题中的问题。

You may use some asynchronous processing, like a method to start a server process and then have the client to check for status/results.您可以使用一些异步处理,例如启动服务器进程然后让客户端检查状态/结果的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM