RMI responding very slow

邮差的信 提交于 2019-12-01 13:05:29

You problem is not the the address that you use for the lookup call to the RMI Registry, but rather it's the address in the URL that is the result of the call to lookup. This defaults to the IP address of the first interface on the system so my guess is that when you're connected to the Internet it's your external connection.

What I think is happening is that you make a call to the RMI Registry on 127.0.0.1 and this returns your Internet address the location of the service you want, and so your RMI call gets routed out over the dongle interface.

You need to set the java.rmi.server.hostname property to tell the RMI Registry which hostname or IP Adress to return in its RMI URLs.

So you'll need something like:

String ipAddress = "10.1.2.3"; //Local IP address 
System.setProperty("java.rmi.server.hostname",ipAddress);

or

String hostname = "myserver"; //hostname that resolves for a local address
System.setProperty("java.rmi.server.hostname",hostname);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!