当我尝试使用Windows XP而不是Linux在memcache.i m中设置密钥时,我的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;
    }
}


stacktrace是:

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,有兴趣= 0}连接队列
2012-06-15 14:30:19.274信息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:设置关键字:勺子标志:1经验值:10数据长度:76,topWop = null,toWrite = 0,有兴趣= 1}
java.io.IOException:意外断开连接,将重新连接。
    在net.spy.memcached.MemcachedConnection.handleReads(MemcachedConnection.java:452)
    在net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:380)
    在net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:242)
    在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:设置键:汤匙标志:1经验值:10数据长度:76,topWop = null,toWrite = 0,有兴趣= 1},尝试0。
2012-06-15 14:30:22.852 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl:丢弃部分完成的操作:Cmd:设置键:勺子标志:1 Exp:10数据长度:76
2012-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,有兴趣= 0}
2012-06-15 14:30:24.868信息net.spy.memcached.MemcachedConnection:sun.nio.ch.SelectionKeyImpl@113beb5的连接状态已更改
2012-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:获取键:spoon Exp:0,topWop = null,toWrite = 0,有兴趣= 1}
java.io.IOException:意外断开连接,将重新连接。
    在net.spy.memcached.MemcachedConnection.handleReads(MemcachedConnection.java:452)
    在net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:380)
    在net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:242)
    在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:获取关键字:spoon Exp:0,topWop = null,toWrite = 0,有兴趣= 1},尝试0。
2012-06-15 14:30:31.665 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl:丢弃部分完成的操作:Cmd:获取键:匙Exp:0
2012-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,有兴趣= 0}
2012-06-15 14:30:33.680信息net.spy.memcached.MemcachedConnection:sun.nio.ch.SelectionKeyImpl@edf389的连接状态已更改
线程“主”中的异常java.lang.RuntimeException:等待值的异常
    在net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1001)
    在net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1018)
    在ballydev.Memcache.main(Memcache.java:39)
引起原因:java.util.concurrent.ExecutionException:java.lang.RuntimeException:已取消
    在net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:103)
    在net.spy.memcached.internal.GetFuture.get(GetFuture.java:62)
    在net.spy.memcached.MemcachedClient.get(MemcachedClient.java:997)
    ...另外2个
引起原因:java.lang.RuntimeException:已取消
    ...另外5个

最佳答案

要调试该问题,请尝试从发出请求的服务器远程登录到内存缓存。如果memcached在启动时明确提及ip地址,则可以拒绝与其他主机的连接。

10-08 00:35