Using Tomcat to run a web app. and I use jedis to connect to our redis server.
Every method that I use is call jedis.close() in finallay block but it look like not return the jedis resources to the pool.
using
netstat -atnlp|grep 6379
The connection count is stile grow. Until jedis client throw the "JedisConnectionException: Could not get a resource from the pool.". I debug the code. jdeis.close() is did run.
Is there any problom whit my Code?
Help me, this has already make our server down for many times.
this is my jedis pom conf
<!-- jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
</dependency>
tomcat is
apache-tomcat-7.0.64
server is
Centos 6.5
redis is
v2.8.11
Spring version:
3.2.13.RELEASE
This is my JedisUtils code:
@Service(value = "redisCacheService")
public class RedisCacheServiceImpl implements CacheService {
/**
* redis Version No.
*/
private static final String VERSION = "000";
private static JedisPool pool;
static {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(500);
config.setMaxIdle(5);
config.setMaxWaitMillis(1000 * 10);
config.setTestOnBorrow(true);
pool = new JedisPool(config, "10.10.65.10", 6379);
}
@Override
public int set(
String key,
String value) {
Jedis jedis = pool.getResource();
try {
return jedis.set(VERSION + "|" + key, value).equals("OK") ? 1 : 0;
} finally {
jedis.close();
}
}
@Override
public int set(
String key,
String value,
int seconds) {
Jedis jedis = pool.getResource();
try {
return jedis.setex(VERSION + "|" + key, seconds, value).equals("OK") ? 1 : 0;
} finally {
jedis.close();
}
}
@Override
public String get(
String key) {
Jedis jedis = pool.getResource();
try {
return jedis.get(VERSION + "|" + key);
} finally {
jedis.close();
}
}
@Override
public int del(
String key) {
Jedis jedis = pool.getResource();
try {
return Integer.valueOf(jedis.del(VERSION + "|" + key).toString());
} finally {
jedis.close();
}
}
@Override
public void setExpire(
String key,
int expireTime) {
Jedis jedis = pool.getResource();
try {
jedis.expire(key, expireTime);
} catch (Exception e) {
jedis.close();
}
}
}
MORE INFO: 2015-11-28 19:58:50
Now the connection count to redis server is still growth.
using jmap to dump all the heap info, and run OQL on jvisualvm:
select x from redis.clients.jedis.Jedis x
Then I found 24 jedis object.
Then I call the jedis method on the same tomcat server again, and dump again. Run the same OQL, there is 25 jedis object found.
maybe this info is helpful.