5

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

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

但是,当我取消部署我的网络应用程序时,在我看来,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.
4

1 回答 1

1

我遇到了同样的问题。设置守护进程对我有用。我正在使用 spymecached-2.8.4 我通过net.spy.memcached.spring.MemcachedClientFactoryBean通过 Spring(spring - 3.1.1)获取 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>
于 2012-11-06T07:09:50.420 回答