java - Redis java.util.NoSuchElementException:池耗尽
问题描述
java.util.concurrent.ExecutionException: java.util.NoSuchElementException: Pool exhausted - Unable to get key(xxx), Exception: java.util.NoSuchElementException: Pool exhausted
当我尝试使用从集群 Redis 获取密钥时出现此错误BoundedAsyncPool
,
private Integer maxTotal = 20;
private Integer maxIdle = 20;
private Integer minIdle = 10 ;
这是我的代码:
@Override
public Object get(String key, Class<?> clazz) {
CompletableFuture<String> getResult = pool.acquire().thenCompose(connection -> {
connection.setReadFrom(ReadFrom.REPLICA);
RedisAdvancedClusterAsyncCommands<String, String> async = connection.async();
return async.get(key).whenComplete((s, throwable) -> pool.release(connection));
});
try {
String value = getResult.get();
if (StringUtils.isEmpty(value)) {
return null;
}
return new ObjectMapper().readValue(value, clazz);
} catch (Exception e) {
LOG.error(e, String.format("Unable to get key(%s), Exception: %s", key, e.getMessage()));
}
return null;
}
解决方案
推荐阅读
- visual-studio-code - 禁用 VSCode 自动更新但允许其他用户设置
- javascript - 如何在我的支付网关结帐过程中结帐时分配商店的订单价值(金额)?
- c# - 自定义编辑器模板未呈现/触发
- c++ - 多核虚假共享
- javascript - 在javascript中显示日期和时间的代码每天下午5点迭代到第二天
- spring - 消费者线程错误,SimpleMessageListenerContainer 上的线程中止
- java - Spring JPA Crud 存储库保存不返回 UUID 字段
- java - 从 spring 模板连接到加密的 Redis 集群
- reactjs - FontAwesomeIcon “已定义但从未使用”,即使它是必需的
- html - 如何仅在 VS 代码的 HTML 片段中更改值?