IOException用于java中memcached中的set操作

时间:2012-06-15 08:48:29

标签: java windows-xp memcached spymemcached

当我尝试使用windows xp而不是linux在memcache.i中设置密钥时,我的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:  Added {QA sa=/10.2.200.104:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2012-06-15 14:30:19.274 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@7cbde6
[/10.2.200.104:11211]
[]
2012-06-15 14:30:22.852 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to exception on {QA sa=/10.2.200.104:11211, #Rops=1, #Wops=0, #iq=0, topRop=Cmd: set Key: spoon Flags: 1 Exp: 10 Data Length: 76, topWop=null, toWrite=0, interested=1}
java.io.IOException: Disconnected unexpected, will reconnect.
    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:  Closing, and reopening {QA sa=/10.2.200.104:11211, #Rops=1, #Wops=0, #iq=0, topRop=Cmd: set Key: spoon Flags: 1 Exp: 10 Data Length: 76, topWop=null, toWrite=0, interested=1}, attempt 0.
2012-06-15 14:30:22.852 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl:  Discarding partially completed op: Cmd: set Key: spoon Flags: 1 Exp: 10 Data Length: 76
2012-06-15 14:30:24.868 INFO net.spy.memcached.MemcachedConnection:  Reconnecting {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:  Connection state changed for sun.nio.ch.SelectionKeyImpl@113beb5
2012-06-15 14:30:31.665 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to exception on {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: Disconnected unexpected, will reconnect.
    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:  Closing, and reopening {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}, attempt 0.
2012-06-15 14:30:31.665 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl:  Discarding partially completed op: Cmd: get Keys: spoon Exp: 0
2012-06-15 14:30:33.680 INFO net.spy.memcached.MemcachedConnection:  Reconnecting {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:  Connection state changed for sun.nio.ch.SelectionKeyImpl@edf389
Exception in thread "main" java.lang.RuntimeException: Exception waiting for value
    at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1001)
    at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1018)
    at ballydev.Memcache.main(Memcache.java:39)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Cancelled
    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 more
Caused by: java.lang.RuntimeException: Cancelled
    ... 5 more

1 个答案:

答案 0 :(得分:1)

要调试此问题,请尝试从发出请求的服务器telnet到memcached。如果明确提到ip地址,则memcached可以拒绝与其他主机的连接。