RMI Connection Timeout Time setting

Source: Internet
Author: User
Tags socket connect



System.setproperty ("Sun.rmi.transport.tcp.responseTimeout", "2000");
System.setproperty ("Sun.rmi.transport.tcp.readTimeout", "2000");
System.setproperty ("Sun.rmi.transport.connectionTimeout", "2000");
System.setproperty ("Sun.rmi.transport.proxy.connectTimeout", "2000");
System.setproperty ("Sun.rmi.transport.tcp.handshakeTimeout", "2000");






I would like to ask the mother can only wait until the above content, but when we set up, also not good, this time we have doubts whether the value of our validation does not affect the content. In fact, the data inside has been rewritten.



Do a bit of analysis:



In the end, the link timeout should be "Sun.rmi.transport.proxy.connectTimeout". In fact, the Sun explains the document in this way:



The value of the represents the maximum length of time (in milliseconds) that the Java RMI runtime would wait for A connection attempt (createSocket) to complete, before attempting to contact the server using HTTP. This property was only used when the property was set and thehttp.proxyHostvalue ofjava.rmi.server.disableHttpisfalse. The default value is 15000 milliseconds (seconds).



But this time we need to see the "http.proxyHost" and "Java.rmi.server.disableHttp" properties, "This is the only used when ...".



The class that the attribute acts on is: rmimastersocketfactory, someone will ask me how to know, this well, I say experience letter? "Look" a joke. You can see the invocation process in the socket by setting a power outage.



At that time, Rmimastersocketfactory did not provide the source code, and could not find the source code. At that time I can see the attributes in this class have connecttimeout, of course, this cannot be concluded that connecttimeout corresponds to "sun.rmi.transport.proxy.connectTimeout",



We could not see the source code at that time, but we could get the byte code of the class, and in the Getconnecttimeout () method we could see "LDC <string" Sun.rmi.transport.proxy.connectTimeout ">" Content, which means that it uses the "Sun.rmi.transport.proxy.connectTimeout" string, and static{} ("Static constructor Method", which is the same as the object's construction method, The difference is that the method value initializes the static variable) in the method 1223th, 1224 lines (copy the bytecode contents into the editor)



Invokestatic sun.rmi.transport.proxy.RMIMasterSocketFactory.getConnectTimeout (): Long [308]
Putstatic Sun.rmi.transport.proxy.RMIMasterSocketFactory.connectTimeout:long [259]



(Invoke, Static sun.rmi.transport.proxy.RMIMasterSocketFactory.getConnectTimeout (), long): Execute static method in Rmimastersocketfactory Getconnecttimeout, return value is long type)
(Put,static sun.rmi.transport.proxy.RMIMasterSocketFactory.connectTimeout, long): self-awareness.



These two lines represent the execution of the Getconnecttimeout () method, assigning a value to the ConnectTimeout static property (to the source code is ConnectTimeout = Getconnecttimeout ()), So I can see that when we load the Rmimastersocketfactory class, we get the value in the "Sun.rmi.transport.proxy.connectTimeout" property to assign the value to ConnectTimeout.  Said to call System.setproperty ("Sun.rmi.transport.proxy.connectTimeout", "2000") before the program loads the Rmimastersocketfactory class; You can do it.



System.setproperty ("Sun.rmi.transport.proxy.connectTimeout", "2000");
Naming.lookup ("Rmi://xxx.xxx.xxx.xxx:xxxx/xxxxxxxx")



But that's not going to work. Because it says in the document above. There is also a property that is not assigned a value.



Well, I'm giving up on this road, too.



Later in detail, in fact, RMI bottom communication is also using the socket, in the socket connect has a connection, one of which is with a time-out, all this time we are not practical naming to do the lookup, the tools of their own naming can be.



All right, it'll be a fart. Here's the positive solution.



Naming.lookup ("rmi://xxx.xxx.xxx.xxx:xxxx/xxxxxxxx");
Change to ↓↓↓↓↓
Registry Registry = locateregistry.getregistry ("xxx.xxx.xxx.xxx", XXXX, new Rmiclientsocketfactory () {
@Override
Public Socket Createsocket (String host, int port) throws IOException {
Socket socket = new socket ();
Socket.connect (New Inetsocketaddress (host, Port), 2000);
return socket;
}
}); Registry preferably a global one (one IP corresponds to a registry, can be multiple, this is just a suggestion)
Registry.lookup ("xxxxxxxx");



All right. OK. As for the binding object or with naming.rebing, no problem. .....






RMI Connection Timeout Time setting


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.