我遇到这种情况,RMI客户端代码调用一个应该返回byte[]
的远程方法,在服务器端执行此方法期间出于某种原因,可能会发生非常糟糕的事情例如服务器停机或者其他......,在这种情况下,我最终得到一个卡住的线程(堆栈跟踪如下):
ool-4-thread-1" #71 prio=5 os_prio=0 tid=0x000000001a4f6000 nid=0xa30 runnable [0x000000001f7fe000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
- locked <0x0000000759b19aa8> (a java.io.BufferedInputStream)
at java.io.DataInputStream.readByte(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy105.generatePDF(Unknown Source)
at com.etq.reliance.pdf.PDFUtils.generatePDFRemotely(PDFUtils.java:147)
...
我在这里尝试实现的是处理这种情况,我认为我可以通过使用以下RMI属性之一轻松解决此问题:
sun.rmi.transport.connectionTimeout
sun.rmi.transport.tcp.responseTimeout
我甚至试过All the other RMI properties,但似乎没有任何效果。关于如何设置某种读取超时的任何想法?