Java RMI - Client Timeout

眉间皱痕 提交于 2019-11-27 04:16:48

For socket read timeout, you can set your own factory like this,

           RMISocketFactory.setSocketFactory( new RMISocketFactory()
            {
                public Socket createSocket( String host, int port )
                    throws IOException
                {
                    Socket socket = new Socket();
                    socket.setSoTimeout( timeoutMillis );
                    socket.setSoLinger( false, 0 );
                    socket.connect( new InetSocketAddress( host, port ), timeoutMillis );
                    return socket;
                }

                public ServerSocket createServerSocket( int port )
                    throws IOException
                {
                    return new ServerSocket( port );
                }
            } );

I recently encountered this problem as well and found that I needed to set the following Java property in order for an RMI call to timeout on the client side:

sun.rmi.transport.tcp.responseTimeout

Here is the full scoop on these params in newer versions of Java:

oxbow_lakes

There is a system property that you can set.
Something like sun.rmi.transport.connectionTimeout

They are detailed here:
https://docs.oracle.com/javase/7/docs/technotes/guides/rmi/sunrmiproperties.html

You can use custom socket factories. It works fine , It is not static and deprecated and against the system property, it does not apply to the whole JVM. But the point is that the code is on the server side.

Creating a Custom RMI Socket Factory

tomcat config: go to vmoptions set -Dsun.rmi.transport.tcp.responseTimeout=30000 (milliseconds)

websphere config: go to Application servers > server1 > Process definition > Java Virtual Machine set -Dsun.rmi.transport.tcp.responseTimeout=30000 in Generic JVM arguments section

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!