我遇到了以下问题:
我的 Tomcat 因以下线程转储而挂起:
"ajp-bio-28109-exec-1589" - Thread t@1713
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
- waiting on <5c1a77ba> (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
at java.lang.Object.wait(Object.java:503)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1118)
at redis.clients.util.Pool.getResource(Pool.java:24)
我的应用程序使用带有 Jedis 客户端的 Redis 数据库。我有大约 2K 请求/秒。 几个小时后,每个线程都在等待。
会不会是 DBCP 问题? 有没有其他方法可以使用 Redis/Jedis 创建连接池?
谢谢
最佳答案
这可能是由于使用默认的 whenExhaustedAction 设置引起的,该设置将阻塞(调用 Object.wait())直到有新的或空闲的对象可用。检查 javadoc here .
您可能需要增加您的 maxActive 值或设置适当的 maxWait。
正如@xetorthio 提到的,完成后您必须返回 jedis 资源:
Jedis jedis = pool.getResource();
try {
/// ... do stuff here ... for example
jedis.set("foo", "bar");
String foobar = jedis.get("foo");
jedis.zadd("sose", 0, "car"); jedis.zadd("sose", 0, "bike");
Set<String> sose = jedis.zrange("sose", 0, -1);
} finally {
/// ... it's important to return the Jedis instance to the pool once you've finished using it
pool.returnResource(jedis);
}
/// ... when closing your application:
pool.destroy();
希望这对您有所帮助。
关于tomcat - Redis/Jedis - Tomcat 挂起 - - 等待 <5c1a77ba>(一个 org.apache.commons.pool.impl.GenericObjectPool$Latch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11977520/