Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 绝地武士:无法从池中获取资源 背景_Java_Redis_Jedis_Nosql - Fatal编程技术网

Java 绝地武士:无法从池中获取资源 背景

Java 绝地武士:无法从池中获取资源 背景,java,redis,jedis,nosql,Java,Redis,Jedis,Nosql,我们的应用程序使用Jedis-2.2.1并连接到Redis-2.6,以下是我获取Jedis资源的方法: protected static JedisWrapper getRedisUserWrite(String UDID) { if (redisUserWritePools.get(0) == null) init(); int hash = hash(UDID); Jedis jedis = redisUserWritePools.get(h

我们的应用程序使用
Jedis-2.2.1
并连接到
Redis-2.6
,以下是我获取Jedis资源的方法:

protected static JedisWrapper getRedisUserWrite(String UDID) {
        if (redisUserWritePools.get(0) == null) init();

        int hash = hash(UDID);
        Jedis jedis = redisUserWritePools.get(hash).getResource();
        jedis.select(dbs.get("redisUserWritePools" + hash));

        return new JedisWrapper(jedis, redisUserWritePools.get(hash));
    }
这是我的绝地说唱者(统一资源管理):

绝地说唱者
是绝地实例的容器,以下是我如何使用它:

private static void cacheSDKIDs(String UDID, String[] SDKIDs) {

        JedisWrapper wrapper = getRedisUserWrite(UDID);
        try {
            if (SDKIDs != null) {
                wrapper.get().del(UDID);
                wrapper.get().sadd(UDID, SDKIDs);
            }
        } catch (JedisConnectionException e) {
            e.printStackTrace();
            wrapper.returnBrokenResource();
        }catch (Exception e) {
            e.printStackTrace();
        } finally {
            wrapper.returnResource();
        }
    }
请注意,
SKDIDs
可能非常大(例如可能达到最大8KB)

问题出在这里 每次我重新启动应用程序时,所有redis连接都是正常的,但需要几个小时 稍后,
无法从池中获取资源
异常出现。频率越来越高,那么所有与Redis的连接都会断开,并可以创建新的连接

以下是我的配置:

<bean id = "redisConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxActive"  value="400" />
    <property name="maxIdle" value="100" />
    <property name="minIdle" value="20" />
    <property name="maxWait" value="4000" />
    <property name="testOnBorrow"  value="true"/>
    <property name="testOnReturn" value="true" />
  </bean>

在你的绝地说唱机中,绝地被创建为一个类变量,该类变量被实例化一次。请在getJedis方法中声明,然后问题将得到解决

检查您是否有权限通过代码访问redis

我遇到了类似的问题。如果你想解决这个问题,我会向你汇报一切可行的方法。问题解决了吗?我面临着类似的问题这是唯一一个使用绝地说唱的地方吗?
<bean id = "redisConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxActive"  value="400" />
    <property name="maxIdle" value="100" />
    <property name="minIdle" value="20" />
    <property name="maxWait" value="4000" />
    <property name="testOnBorrow"  value="true"/>
    <property name="testOnReturn" value="true" />
  </bean>
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
    at redis.clients.util.Pool.getResource(Pool.java:40)
    at com.xxxice.redis.BaseRedis.getRedisUserWrite(BaseRedis.java:158)
    at com.xxx.service.redis.DeviceRedis.cacheSDKIds(DeviceRedis.java:128)
    at com.xxx.redis.DeviceRedis.cacheDevice(DeviceRedis.java:65)
    at com.xxx.service.DeviceService.update(DeviceService.java:88)
    at com.xxx.controller.Devices.update(Devices.java:25)
    ... 32 more
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
    at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1174)
    at redis.clients.util.Pool.getResource(Pool.java:38)
    ... 37 more