您的位置:首页 > 数据库 > Memcache

Memcached ++++ exception thrown while trying to get object from cache for key

2017-08-15 09:05 1021 查看

Memcached ++++ exception thrown while trying to get object from cache for key  

2016-10-20 14:57:13|  分类:

默认分类 |  标签:memcached  xmemcached  memcached客户端  
|举报
|字号大中小 订阅

 

 
  

++++ exception thrown while writing bytes to server on set
您的主机中的软件中止了一个已建立的连接
java.io.IOException: 您的主机中的软件中止了一个已建立的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)
at sun.nio.ch.IOUtil.read(IOUtil.java:206)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)
at sun.nio.ch.SocketAdaptor$SocketInputStream.read(SocketAdaptor.java:184)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:86)

隔一段时间不访问,一开始访问就报错。
使用的客户端是com.danga.memcached
怀疑是客户端问题
最后换成客户端:
com.whalin.Memcached-Java-Client
问题解决,会不会再出现,等后面再观察。

进过观察,换了memcached服务器版本,客户端版本,已经尝试的客户端的各个参数,参数设置会延迟刷新的时候,但是久了后还是会出现断掉的情况,猜想原因:客户端在维护socket池的时候出现了bug,在检查的时候,没把有问题的连接给关掉。导致第一次访问那个缓存还是之前的问题连接,然后就报错。
解决办法:换成xmemcached 客户端,xmemcached 是采用nio的方式,理论上是可以不用维持数据池的,尝试效果,目前没出现这种情况。一下是跟spring整合的配置。
pom

<dependency>
<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached</artifactId>
<version>2.0.0</version>
</dependency>

properties 

memcache.server=xx
memcache.port=xx
memcache.connectionPoolSize=10

spring 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean id="memcachedClientBuilder" class="net.rubyeye.xmemcached.XMemcachedClientBuilder">
<constructor-arg>
<list>
<bean class="java.net.InetSocketAddress">
<constructor-arg value="${memcache.server}" />
<constructor-arg value="${memcache.port}" />
</bean>
</list>
</constructor-arg>
<property name="connectionPoolSize" value="${memcache.connectionPoolSize}" />
<property name="commandFactory">
<bean class="net.rubyeye.xmemcached.command.BinaryCommandFactory" />
</property>
<property name="transcoder">
<bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" />
</property>
</bean>
<bean id="xmemcachedClient" factory-bean="memcachedClientBuilder"
factory-method="build" destroy-method="shutdown" />

</beans>

使用:

@Resource
MemcachedClient xmemcachedClient;

@Override
public List<Configuration> getList() {
List<Configuration> result = null;
try {
result = (List<Configuration>) xmemcachedClient.get("configurationgetList");
if (result == null) {
result = session.select(0, 0);
xmemcachedClient.set("configurationgetList", DateUtil.oneDayCache, result);
}
} catch (TimeoutException e1) {
e1.printStackTrace();
} catch (InterruptedException e1) {
e1.printStackTrace();
} catch (MemcachedException e1) {
e1.printStackTrace();
}
return result;

}

回复

上一页
1
... -1
-1 -1
-1 -1
-1 -1
... -1
下一页
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐