我已经在tomcat容器中部署了我的Web应用程序,但是由于可能的连接泄漏,Web应用程序不断尝试连接到侦听端口11211和11212的本地memcached服务器失败。我正在使用spy-memcached客户端。
我定义了一个ContextListener,它基本上关闭了所有活动的memcached客户端连接。
然而,当我取消部署我的Web应用程序时,在我看来tomcat仍在尝试继续尝试连接到memcached服务器失败,它不应该。我已经检查了memcached服务器上的活动tcp连接netstat但我找不到任何条目。
我也重新启动了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.
答案 0 :(得分:0)
我遇到了同样的问题。设置守护进程真的对我有用。我正在使用spymecached-2.8.4我通过 net.spy.memcached.spring.MemcachedClientFactoryBean 通过Spring(spring - 3.1.1)获取Memcached客户端,这是我在我使用的弹簧配置网络应用:
<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>