Search code examples
javamultithreadingrmi

RMI: thread waiting on server side


I have the following code:

public interface RmiServer extends Remote{
   public String getMessage()throws RemoteException;
}

public class DefaultRmiServer implements RmiServer{
  private LinkedBlockingQueue<String> queue;

  @Override
  public String getMessage()throws RemoteException{
    return queue.take();
  }
  ...
}

When rmi client calls getMessage() method it is clear that there can be two situations:

  1. there is a message in queue and method returns
  2. there is no message in queue and thread is waiting

What will happen in the second case with this rmi call? How long the client will wait?


Solution

  • Sun RMI client connection's timout is being controlled by the property sun.rmi.transport.tcp.responseTimeout, which is by default set to no timeout (=waits forever).

    sun.rmi.transport.tcp.responseTimeout (1.4 and later):

    The value of this property represents the length of time (in milliseconds) that the client-side Java RMI runtime will use as a socket read timeout on an established JRMP connection when reading response data for a remote method invocation. Therefore, this property can be used to impose a timeout on waiting for the results of remote invocations; if this timeout expires, the associated invocation will fail with a java.rmi.RemoteException. Setting this property should be done with due consideration, however, because it effectively places an upper bound on the allowed duration of any successful outgoing remote invocation. The maximum value is Integer.MAX_VALUE, and a value of zero indicates an infinite timeout. The default value is zero (no timeout).

    For the list of this and other parameters that can used to control RMI connections see sun.rmi Properties