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

Java 如何阻止tomcat尝试连接本地memcached服务器失败?,java,tomcat,memcached,spymemcached,Java,Tomcat,Memcached,Spymemcached,我已经在tomcat容器中部署了我的web应用程序,但由于可能存在连接泄漏,该web应用程序不断尝试连接到本地memcached服务器(侦听端口11211和11212)失败。我正在使用spy memcached客户端 我定义了一个ContextListener,它基本上关闭所有活动的memcached客户端连接 但是,当我取消部署web应用程序时,tomcat似乎仍在尝试继续尝试连接到memcached服务器,但失败的尝试不应该继续。我已使用netstat检查memcached服务器上的活动tc

我已经在tomcat容器中部署了我的web应用程序,但由于可能存在连接泄漏,该web应用程序不断尝试连接到本地memcached服务器(侦听端口11211和11212)失败。我正在使用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.

我也面临着同样的问题。设置daemon true对我来说很有效。我使用的是spymecached-2.8.4。我通过net.spy.Memcached.spring.Memcached客户端通过spring(spring-3.1.1)获取Memcached客户端,下面是我在web应用程序中使用的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>

凯塔玛乌哈什

重新连接尝试是否会导致问题?这是一个需要解决的问题吗?它们本身并没有造成任何问题,但它们只是悬空的重新连接,这让我感到困扰,因为它填满了我的整个日志空间。不知何故,我不得不手动终止从8080端口到11211和11212端口的所有传入连接,我想这对我来说已经有点效果了。但我仍然不明白为什么即使在上下文被破坏之后,陈旧的连接仍然会持续存在??我也有同样的问题,环境是Spymecached 2.8.1,linux上的tomcat 6 2.6.18.2-34-default。在ServletContextListener的contextDestroyed中调用MemcachedClient shutdown。奇怪的是错误消息说:2012-06-28 11:00:39.753 INFO net.spy.memcached.memcached连接:重新连接{QA sa=/127.0.0.1:11211,#Rops=0,#Wops=0,#iq=0,topRop=null,topWop=null,toWrite=0,interest=0}但是我曾经在我的应用程序中使用过端口11212,不知怎的,它默认为11211…我认为SpymeMached小组的这个线程描述的是同一个问题。但是,设置守护进程和调用shutdown没有帮助。