记着,防止以后忘记
代码如下:
package com.tyro.redis;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* redis连接池
* @author Administrator
*
*/
public class JedisPoolUtil {
private static volatile JedisPool jedisPool = null;
private JedisPoolUtil() {
}
/**
* 获取实例
* @return
*/
public static JedisPool getJedisPoolInstance(){
if(jedisPool == null){
synchronized(JedisPool.class){
if(jedisPool == null){
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxActive(500);
config.setMaxIdle(32);
config.setMaxWait(10*1000);
config.setTestOnBorrow(true);
System.out.println("--------------------------------------------------------initialPool");
jedisPool = new JedisPool(config,"127.0.0.1",6379);
// jedisPool = new JedisPool(config,"host",6379,3000,"password");
}
}
}
return jedisPool;
}
/**
* 释放资源
* @param jedisPool
* @param jedis
*/
public static void release(JedisPool jedisPool,Jedis jedis){
if(jedis != null){
System.out.println("******释放******");
jedisPool.returnResourceObject(jedis);
}
}
}
这个jedis版本好像是2.1.0的,最新版本没有setMaxActive方法了。改如下:
config.setMaxTotal(500);// 代替config.setMaxActive(500)
config.setMaxWaitMillis(10*1000); //代替config.setMaxWait(10*1000);
ok,笔记做完
网友评论