Skip to main content

How to set RMI client read timeout

No replies
Joined: 2012-10-24


How can I set an RMI read timeout on the client side.

I'd like to do it for two reasons:

1) So I can control the user experience

2) If the client makes an RMI call that takes a very long time to return, or never returns, then Glassfish can't be shut down. After I've tried to shut it down I can see that RMI sockets are being created, so I presume that there is an ORB thread running indefinitely trying to honour the RMI request. The only way I have found to stop Glassfish in this condition is to boot the host. Clumsy !

I've tried:

1) Creating an RMI socket factory on the server side on the understanding that the server will create the client RMI socket and send it to the client to use;

in my socket factory I create sockets with timeouts already set; this doesn't do much because, as others have discovered, the server resets the timeout after getting a socket from the factory; to overcome this my socket factory creates sockets that subclass Socket and change any attempt to change the socket timeout from the value that I set. This happens whether the server calls setSoTimeout or attempts to connect with a timeout parameter.

I can see from trace that the server's attempts to reset the socket timeout are defeated.

Problem is either the server doesn't send a socket to the client or the client ignores it. Certainly the timeouts that I set don't work on the client side. Also I don't see any trace to suggest that the client has used one of my sockets to attempt to connect to the server - I've got tracing in both connect methods.

2) Exploiting the above I have set the RMI socket factory on the client side to be the socket factory above. I can see from trace that this happens. If I try it twice it fails, as it should, indicating that it was actually set the first time. I have trace set to show if the client uses the factory. it doesn't. So this doesn't work to set the timeouts either.

3) Setting property-based timeouts. There are a couple of references on the web to such property based timeout settings. But they are all old and none seem to work. This makes sense because the current Glassfish documentation lists the tuneable ORB parameters and there are no read or connect timeout settings among them.