Jedis: konnte keine Ressource aus dem Pool bekommenJava

Java-Forum
Anonymous
 Jedis: konnte keine Ressource aus dem Pool bekommen

Post by Anonymous »

Hintergrund < /h2>

Unsere Anwendung verwendet JEDIS-2.2.1 < /code> und stellt eine Verbindung zu Redis-2.6 < /code>. So erhalte ich Jedis-Ressource: < /p>

Code: Select all

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));
}
< /code>

Und dies ist mein jediswrapper < /code> (entfernen Sie die Verwaltung von Ressourcen): < /p>

public class JedisWrapper {
private Jedis jedis;
private JedisPool pool;

public JedisWrapper(Jedis jedis, JedisPool pool) {
this.jedis = jedis;
this.pool = pool;
}

public Jedis get(){
return this.jedis;
}

public void returnResource() {
if(null != this.jedis){
this.pool.returnResource(this.jedis);
}
}

public void returnBrokenResource() {
if(null != this.jedis) {
this.pool.returnBrokenResource(this.jedis);
}
this.jedis = null;
}
}
< /code>

JedisWrapper< /code> ist der Container, wenn Jedis -Instanz, hier verwendet ich: < /p>

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();
}
}
< /code>

Note that, SKDIDs< /code> Vielleicht sehr groß (z. B. könnte das Maximum von 8 KB erreichen). Und die Frequenz werden immer höher, dann werden alle Verbindungen zu Redis getrennt und können eine neue Verbindung herstellen.







< /code>

Exception Stacktrace:

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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post