配置Jedis连接池时,JedisPoolConfig中没有SetMaxTotal(),setMaxIdle()等方法

初次接触redis数据库,并使用Jedis连接池连接redis数据库

起初使用的jar包为jedis-2.4.2.jar和commons-pool-1.6.jar



import org.junit.Test;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class Demo2 {
/**
* 连接池
*/
@Test
public void run1() {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(50);//此处报错
config.setMaxIdle(10);//此处报错
JedisPool pool = new JedisPool(config, "192.168.149.128", 6379);//此处报错
Jedis jedis = pool.getResource();
System.out.println(jedis.get("name"));
jedis.close();
}
}

调查发现JedisPoolConfig.class内容(反编译)如下:

/*jadclipse*/// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.


package redis.clients.jedis;


import org.apache.commons.pool2.impl.GenericObjectPoolConfig;


public class JedisPoolConfig extends GenericObjectPoolConfig
{


    public JedisPoolConfig()
    {
        setTestWhileIdle(true);
        setMinEvictableIdleTimeMillis(60000L);
        setTimeBetweenEvictionRunsMillis(30000L);
        setNumTestsPerEvictionRun(-1);
    }
}




/*
DECOMPILATION REPORT


Decompiled from: D:\android\project_1\Jedis_Project\WebContent\WEB-INF\lib\jedis-2.4.2.jar
Total time: 84 ms
Jad reported messages/errors:
The class file version is 50.0 (only 45.3, 46.0 and 47.0 are supported)
Exit status: 0
Caught exceptions:
*/

原来JedisPoolConfig的父类是org.apache.commons.pool2.impl下面的GenericObjectPoolConfig类,而本次导入的

commons-pool为pool1的,非pool2的,故项目中没有找到其SetMaxTotal(),setMaxIdle()等方法,

进而决定重新导入pool2的jar包,这次导入的commons-pool.jar的版本为2-3.3(commons-pool2-2.3.jar),jedis包依旧为jedis-2.4.2.jar

这样设定后,项目没有报错,正常测试



你可能感兴趣的:(redis连接池)