如何阻止 tomcat 尝试连接到本地 memcached 服务器失败?

A N*_*ter 5 java memcached tomcat spymemcached

我已经在 tomcat 容器中部署了我的 web 应用程序,但由于可能存在连接泄漏,web 应用程序不断尝试连接到侦听端口 11211 和 11212 的本地 memcached 服务器失败。我正在使用 spy-memcached 客户端。

我定义了一个 ContextListener ,它基本上关闭了所有活动的 memcached 客户端连接。

但是,当我取消部署我的 web 应用程序时,在我看来 tomcat 仍在尝试继续尝试连接到 memcached 服务器的失败尝试,它不应该。我已经使用 netstat 检查了 memcached 服务器上的活动 tcp 连接,但我找不到任何条目。

我也重新启动了 tomcat 服务器,但无济于事。

我应该如何限制 tomcat 进行这些连接?

2011-11-13 21:21:34.575 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=localhost/127.0.0.1:11212, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:407)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:275)
    at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:2030)
2011-11-13 21:21:34.576 WARN net.spy.memcached.MemcachedConnection:  Closing, and reopening {QA sa=localhost/127.0.0.1:11212, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 32.
Run Code Online (Sandbox Code Playgroud)

Asr*_*que 1

我面临着同样的问题。设置 daemon true 对我有用。我使用的是spymecached-2.8.4,我通过Spring(spring - 3.1.1)通过net.spy.memcached.spring.MemcachedClientFactoryBean获取Memcached客户端,这是我在网络应用程序中使用的spring配置:

<bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean">
        <property name="servers" value="localhost:11211"/>
        <property name="protocol" value="BINARY"/>

        <property name="transcoder">
            <bean class="net.spy.memcached.transcoders.SerializingTranscoder">
                <property name="compressionThreshold" value="1024"/>
            </bean>
        </property>

        <property name="opTimeout" value="1000"/>
        <property name="timeoutExceptionThreshold" value="1998"/>
        <property name="hashAlg">
            <value type="net.spy.memcached.DefaultHashAlgorithm">KETAMA_HASH</value>
        </property>
        <property name="locatorType" value="CONSISTENT"/>
        <property name="failureMode" value="Redistribute"/>
        <property name="useNagleAlgorithm" value="false"/>
        <property name="daemon" value="true"/>

    </bean>
Run Code Online (Sandbox Code Playgroud)