IOException for set operation in memcached in java



当我尝试在memcache中设置密钥时,我的java代码给出了ioexception和memcache服务器重新连接

法典:

public class Memcache implements Serializable  {
    MemcachedClient client;
    public static final int EXP_TIME = 10;
    public static final String KEY = "spoon";
    public static void main(String[] args)throws IOException{
        Memcache temp=new Memcache();
        Dummy dummy= new Dummy("Hello World");
        try {
           temp.client = new MemcachedClient(new InetSocketAddress("localhost", 11211));
        } catch (IOException e) {
           e.printStackTrace();
           System.err.println("connection problem");
        }
        temp.obj=temp.client.getAvailableServers();
        System.out.println(temp.obj);
        temp.obj1=temp.client.getUnavailableServers();
        System.out.println(temp.obj1);
        temp.client.add(KEY, EXP_TIME, dummy);
        Object myObject=temp.client.get(KEY);
        System.out.println(myObject);
        temp.client.delete(KEY);
    }
}

我调试了代码,但是当它达到设置操作时,它断开了IOException n。

虚拟人的代码是:

import java.io.Serializable;
public class Dummy implements Serializable {
    String one;
    public Dummy(String one){
        this.one=one;
    }
}

堆栈跟踪是:

2012-06-15 14:30:19.259 INFO net.spy.memcached.MemcachedConnection: 添加了 {QA sa=/10.2.200.104:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} 连接队列2012-06-15 14:30:19.274 INFO net.spy.memcached.MemcachedConnection: 连接状态更改sun.nio.ch.SelectionKeyImpl@7cbde6[/10.2.200.104:11211][]2012-06-15 14:30:22.852 INFO net.spy.memcached.MemcachedConnection: 由于 {QA sa=/10.2.200.104:11211, #Rops=1, #Wops=0, #iq=0, topRop=Cmd: set 键: 勺子 标志: 1 经验: 10 数据长度: 76, topWop=null, toWrite=0, interested=1}java.io.IOException:意外断开连接,将重新连接。    at net.spy.memcached.MemcachedConnection.handleReads(MemcachedConnection.java:452)    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:380)    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:242)    at net.spy.memcached.MemcachedConnection.run(MemcachedConnection.java:833)2012-06-15 14:30:22.852 WARN net.spy.memcached.MemcachedConnection: 关闭,然后重新打开 {QA sa=/10.2.200.104:11211, #Rops=1, #Wops=0, #iq=0, topRop=Cmd: set 键: 勺子 标志: 1 经验: 10 数据长度: 76, topWop=null, toWrite=0, interested=1}, try 0.2012-06-15 14:30:22.852 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl: 丢弃部分完成的操作: Cmd: set 键: 勺子 标志: 1 经验: 10 数据长度: 762012-06-15 14:30:24.868 INFO net.spy.memcached.MemcachedConnection: 重新连接 {QA sa=/10.2.200.104:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}2012-06-15 14:30:24.868 INFO net.spy.memcached.MemcachedConnection: 连接状态更改sun.nio.ch.SelectionKeyImpl@113beb52012-06-15 14:30:31.665 INFO net.spy.memcached.MemcachedConnection: 由于 {QA sa=/10.2.200.104:11211, #Rops=1, #Wops=0, #iq=0, topRop=Cmd: get Keys: spoon Exp: 0, topWop=null, toWrite=0, interested=1}java.io.IOException:意外断开连接,将重新连接。    at net.spy.memcached.MemcachedConnection.handleReads(MemcachedConnection.java:452)    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:380)    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:242)    at net.spy.memcached.MemcachedConnection.run(MemcachedConnection.java:833)2012-06-15 14:30:31.665 WARN net.spy.memcached.MemcachedConnection: 关闭,然后重新打开 {QA sa=/10.2.200.104:11211, #Rops=1, #Wops=0, #iq=0, topRop=Cmd: get Keys: spoon Exp: 0, topWop=null, toWrite=0, interested=1}, try 0.2012-06-15 14:30:31.665 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl: 丢弃部分完成的操作: Cmd: get 键: spoon Exp: 02012-06-15 14:30:33.680 INFO net.spy.memcached.MemcachedConnection: 重新连接 {QA sa=/10.2.200.104:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}2012-06-15 14:30:33.680 INFO net.spy.memcached.MemcachedConnection: 连接状态更改sun.nio.ch.SelectionKeyImpl@edf389线程"main"中的异常 java.lang.RuntimeException: 等待值的异常    at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1001)    at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1018)    在巴利德夫。Memcache.main(Memcache.java:39)原因:java.util.concurrent.ExecutionException: java.lang.RuntimeException: Cancel(已取消)    at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:103)    at net.spy.memcached.internal.GetFuture.get(GetFuture.java:62)    at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:997)    ...2 更多原因:java.lang.Runtime异常:已取消    ...5 更多

要调试此问题,请尝试从发出请求的服务器远程登录到 memcached。如果 memcached 开始明确提及 IP 地址,则它可以拒绝与其他主机的连接。

最新更新