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

Redis的java客户端JRedis1.0RC退出时的bug

2011-01-26 11:14 288 查看
Redis的java版客户端有两个:JDBC-Redis 和 JRedis,听了好多评论说JDBC-Redis的性能并不怎么样,so直接使用JRedis。

在测试并发的时候,为了模拟项目实际的场景,所以每次的增读都调用一次JRedisClient的ping即建立连接操作(当然可以将客户端维护起来而不更多的建立连接,问题可能就不出现了,这里只讨论问题),如此运行几次之后,客户端抛出异常

Java代码



Exception in thread "Thread-1270" java.lang.OutOfMemoryError: Java heap space

Exception in thread "Thread-1270" java.lang.OutOfMemoryError: Java heap space


经过查看线程数,确认是客户端中存在了很多的线程没有被关闭掉所致。

使用JRedis1.0RC版中给定的测试类HelloAgain进行DEBUG看了一下这些启动的线程,发现后台启动了一个守护线程跟Redis服务端作heartbeart,但是在执行jredis.quit()后却并没有退出,图示如下:



run的代码为:

Java代码



private void run(String password) {

try {

JRedis jredis = new JRedisClient("10.10.13.31", 6379, "jredis", 0);

jredis.ping();

if (!jredis.exists(key)) {

jredis.set(key, "Hello Again!");

System.out.format("Hello! You should run me again!/n");

} else {

String msg = toStr(jredis.get(key));

System.out.format("%s/n", msg);

}

jredis.quit(); //注意这行,方法注释为:Disconnects the client

} catch (RedisException e) {

//省略

}

}

private void run(String password) {
try {
JRedis jredis = new JRedisClient("10.10.13.31", 6379, "jredis", 0);
jredis.ping();

if (!jredis.exists(key)) {
jredis.set(key, "Hello Again!");
System.out.format("Hello!  You should run me again!/n");
} else {
String msg = toStr(jredis.get(key));
System.out.format("%s/n", msg);
}
jredis.quit(); //注意这行,方法注释为:Disconnects the client
} catch (RedisException e) {
//省略
}
}


我想这应该是bug吧,呵呵。等会再去Jredis网站上看一眼,是否对它进行了修复。。。

from: http://www.javaeye.com/topic/668657
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: