RMI:在服务器端等待的线程
RMI: thread waiting on server side
我有以下代码:
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();
}
...
}
当rmi client调用getMessage()
方法时,很明显可以有两种情况:
- 队列和方法中有一条消息returns
- 队列中有
no
条消息,线程正在等待
在第二种情况下这个 rmi 调用会发生什么?客户要等多久?
Sun RMI 客户端连接的超时由 属性 sun.rmi.transport.tcp.responseTimeout
控制,默认设置为无超时(=永远等待)。
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).
有关可用于控制 RMI 连接的此参数和其他参数的列表,请参阅 sun.rmi Properties
我有以下代码:
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();
}
...
}
当rmi client调用getMessage()
方法时,很明显可以有两种情况:
- 队列和方法中有一条消息returns
- 队列中有
no
条消息,线程正在等待
在第二种情况下这个 rmi 调用会发生什么?客户要等多久?
Sun RMI 客户端连接的超时由 属性 sun.rmi.transport.tcp.responseTimeout
控制,默认设置为无超时(=永远等待)。
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).
有关可用于控制 RMI 连接的此参数和其他参数的列表,请参阅 sun.rmi Properties