现在服务端加了超时设置:
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="8088"/>
</bean>
   <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="ParPriceService"></property>
<property name="service" ref="parPriceService"></property>
<property name="serviceInterface"
value="com.qunar.service.ParPriceService"></property>
<!-- <property name="registryPort" value="8088"></property>
<property name="servicePort" value="8088"></property> -->
<property name="registry" ref="registry"></property>
<property name="clientSocketFactory" ref="rmiClientSocketFactory" />
<property name="serverSocketFactory" ref="rmiServerSocketFactory" />
</bean>

<bean id="rmiClientSocketFactory" class="com.qunar.rmi.RMICustomClientSocketFactory">   
        <property name="timeout" value="5000"></property><!--这里配置的是client的读超时-->
    </bean>

<bean id="rmiServerSocketFactory" class="com.qunar.rmi.RMICustomServerSocketFactory">   
        <property name="timeout" value="5000"></property> <!--这里配置的是server监听请求超时设置,5S内无请求server端会抛异常-->
    </bean>客户端配置了自动重连
<bean id="rmiClientSocketFactory" class="com.qunar.rmi.RMICustomClientSocketFactory">
<property name="timeout" value="5000"></property>
</bean>

<bean id="rmiParPriceService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">  
        <property name="serviceUrl" value="rmi://192.168.0.95:8088/ParPriceService" />  
        <property name="serviceInterface"
            value="com.qunar.service.ParPriceService"/>
        <property name="refreshStubOnConnectFailure" value="true"></property>
<property name="lookupStubOnStartup" value="false"></property>
<property name="registryClientSocketFactory" ref="rmiClientSocketFactory"></property>
    </bean>但是访问到一定的时间之后还是会报错 

解决方案 »

  1.   


    <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
    <property name="port" value="8088"/>
    </bean>
       <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
    <property name="serviceName" value="ParPriceService"></property>
    <property name="service" ref="parPriceService"></property>
    <property name="serviceInterface"
    value="com.qunar.service.ParPriceService"></property>
    <!-- <property name="registryPort" value="8088"></property>
    <property name="servicePort" value="8088"></property> -->
    <property name="registry" ref="registry"></property>
    <property name="clientSocketFactory" ref="rmiClientSocketFactory" />
    <property name="serverSocketFactory" ref="rmiServerSocketFactory" />
    </bean>

    <bean id="rmiClientSocketFactory" class="com.qunar.rmi.RMICustomClientSocketFactory">   
            <property name="timeout" value="5000"></property><!--这里配置的是client的读超时-->
        </bean>

    <bean id="rmiServerSocketFactory" class="com.qunar.rmi.RMICustomServerSocketFactory">   
            <property name="timeout" value="5000"></property> <!--这里配置的是server监听请求超时设置,5S内无请求server端会抛异常-->
        </bean>
      

  2.   


    org.springframework.remoting.RemoteAccessException: Could not access remote service [rmi://192.168.0.95:8088/ParPriceService]; nested exception is java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: 
    java.net.SocketTimeoutException: Read timed out
    at org.springframework.remoting.rmi.RmiClientInterceptorUtils.convertRmiAccessException(RmiClientInterceptorUtils.java:193)
    at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:347)
    at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:259)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy0.getParPrices(Unknown Source)
    at test.Test$1.run(Test.java:75)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: 
    java.net.SocketTimeoutException: Read timed out
    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.$Proxy1.invoke(Unknown Source)
    at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:398)
    at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:344)
    ... 6 more
    Caused by: java.net.SocketTimeoutException: Read timed out
    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)
    at java.io.DataInputStream.readByte(Unknown Source)
      

  3.   

    客户端报错如下 :org.springframework.remoting.RemoteAccessException: Could not access remote service [rmi://192.168.0.95:8088/ParPriceService]; nested exception is java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: 
    java.net.SocketTimeoutException: Read timed out
    at org.springframework.remoting.rmi.RmiClientInterceptorUtils.convertRmiAccessException(RmiClientInterceptorUtils.java:193)
    at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:347)
    at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:259)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy0.getParPrices(Unknown Source)
    at test.Test$1.run(Test.java:75)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: 
    java.net.SocketTimeoutException: Read timed out
    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.$Proxy1.invoke(Unknown Source)
    at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:398)
    at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:344)
    ... 6 more
    Caused by: java.net.SocketTimeoutException: Read timed out
    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)
    at java.io.DataInputStream.readByte(Unknown Source)