Spring 3.0 RmiProxyFactoryBean:如何设置连接超时? [英] Spring 3.0 RmiProxyFactoryBean: how to set connection timeout?

查看:77
本文介绍了Spring 3.0 RmiProxyFactoryBean:如何设置连接超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 RMI 连接添加测试"功能(检查另一端的服务器是否可用/存在).我已经创建了这个类/beans:

I need to add "test" functionality for RMI connection (checking if the server on the other side is available/existent). I have created this class/beans:

 public class MyRmiClientSocketFactory implements RMIClientSocketFactory {

private int timeout;

public void setTimeout(int timeout) {
    this.timeout = timeout;
}

@Override
public Socket createSocket(String host, int port) throws IOException {
    final Socket socket = new Socket();
    socket.setSoTimeout(timeout);
            socket.setSoLinger(false, 0);
            socket.connect(new InetSocketAddress(host, port), timeout);
    return socket;
}

 }

 <bean id="myRmiClientSocketFactory" class="org.myapp.MyRmiClientSocketFactory">
    <property name="timeout" value="2000"/>
</bean>

 <bean id="myExecutor" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    <property name="serviceInterface" value="org.myapp.MyExecutor"/>
    <property name="serviceUrl" value="rmi://localhost:1099/myExecutor"/>
<!--        <property name="refreshStubOnConnectFailure" value="true"/> -->
<!--        <property name="lookupStubOnStartup" value="false"/> -->
    <property name="registryClientSocketFactory" ref="myRmiClientSocketFactory"/>
</bean>

当我在serviceUrl"中设置一个错误"的 url 时,我希望在 2 秒后出现连接超时",但这不会发生.知道如何使它成为可能吗?

When I set a "wrong" url in "serviceUrl" I expect for a "connection timeout" after 2 seconds but that doesn't happen. Any idea how to make it possible?

推荐答案

您设置的是读取超时,而不是连接超时.调用 connect() 时会发生连接超时.

You've set a read timeout, not a connect timeout. Connect timeouts happen when you call connect().

这篇关于Spring 3.0 RmiProxyFactoryBean:如何设置连接超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆