gpt4 book ai didi

java - java中memcached中设置操作的IOException

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:52 27 4
gpt4 key购买 nike

当我尝试在 memcache.i 中设置 key 时,我的 java 代码给出了 ioexception 且 memcache 服务器重新连接。我使用的是 windows xp 而不是 Linux。

代码:

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:  Added {QA sa=/10.2.200.104:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue2012-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: 762012-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@113beb52012-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: 02012-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@edf389Exception 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 moreCaused by: java.lang.RuntimeException: Cancelled    ... 5 more

最佳答案

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

关于java - java中memcached中设置操作的IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11047393/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com