绝地武士池如何运作?
2022-09-01 05:22:58
我正在使用Jedis池来管理与Redis服务器的连接。我的一个示例代码如下:
public Set<String> getTopArticleList(int start, int end) {
Set<String> list = null;
Jedis j = JedisFactory.getInstance().getJedisPool().getResource();
Pipeline pipe = j.pipelined();
try {
// do stuff with redis
pipe.sync();
} catch (JedisConnectionException jex) {
JedisFactory.getInstance().getJedisPool().returnBrokenResource(j);
} finally {
JedisFactory.getInstance().getJedisPool().returnResource(j);
}
return list;
}
用于创建和检索 Jedis 池的代码:
class JedisFactory {
private static JedisPool jedisPool;
public JedisFactory() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
jedisPool = new JedisPool(
poolConfig,
RedisDBConfig.HOST,
RedisDBConfig.PORT,
RedisDBConfig.TIMEOUT,
RedisDBConfig.PASSWORD
);
}
public JedisPool getJedisPool() {
return jedisPool;
}
public static JedisFactory getInstance() {
if (instance == null) {
instance = new JedisFactory();
}
return instance;
}
}
问题是,在达到有限连接数后,无法再访问Web。我做错了什么吗?