警告 rcjJedisFactory:关闭 redis.clients.jedis.exceptions.JedisException 时出错:无法将损坏的资源返回到池中
我收到以下错误
WARN r.c.j.JedisFactory: Error while close
redis.clients.jedis.exceptions.JedisException: Could not return the broken resource to the pool
请告诉我如何修复它。因为我经常收到此错误。我认为还需要将一些东西包装在“try”和“catch”中。还是其他方面有问题?我很乐意提供帮助。
代码如下所示。
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.List;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.jmeter.samplers.SampleResult;
JedisPool jedisPool = (JedisPool) props.get('jedisPool');
Jedis jedis = jedisPool.getResource();
List<Object> execResult = null;
String GetIncrNumber;
int countTry = 0;
while(execResult == null) {
try{
jedis.watch("Number");
Transaction t = jedis.multi();
Response<String> rs = t.incr("Number");
execResult = t.exec();
GetIncrNumber = rs.get();
t.close();
t = null;
rs = null;
} catch (Exception e){
countTry++;
sleep(50);
if(countTry > 15){
log.error("\r\nSome error (countTry = " + countTry + ") GetIncrNumber: " + e.getMessage() + "\r\n");
}
}
}
execResult.clear();
vars.put("GetIncrNumber_JM", GetIncrNumber.toString());
//log.info(GetIncrNumber)
jedisPool.returnResource(jedis);
execResult = null;
jedis = null;
jedisPool = null;
I get the following error
WARN r.c.j.JedisFactory: Error while close
redis.clients.jedis.exceptions.JedisException: Could not return the broken resource to the pool
Please tell me how it can be fixed. Because I get this error regularly. I think that there is an additional need to wrap something in "try" and "catch". Or is there a problem in something else ? I will be glad to help.
The code looks like this.
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.List;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.jmeter.samplers.SampleResult;
JedisPool jedisPool = (JedisPool) props.get('jedisPool');
Jedis jedis = jedisPool.getResource();
List<Object> execResult = null;
String GetIncrNumber;
int countTry = 0;
while(execResult == null) {
try{
jedis.watch("Number");
Transaction t = jedis.multi();
Response<String> rs = t.incr("Number");
execResult = t.exec();
GetIncrNumber = rs.get();
t.close();
t = null;
rs = null;
} catch (Exception e){
countTry++;
sleep(50);
if(countTry > 15){
log.error("\r\nSome error (countTry = " + countTry + ") GetIncrNumber: " + e.getMessage() + "\r\n");
}
}
}
execResult.clear();
vars.put("GetIncrNumber_JM", GetIncrNumber.toString());
//log.info(GetIncrNumber)
jedisPool.returnResource(jedis);
execResult = null;
jedis = null;
jedisPool = null;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你应该打电话 JedisPool.returnBrokenResource() 某处 finally 阻止并捕获更具体的异常?
您还可以考虑使用 Jedis.close() 相反。
顺便说一句,您是否考虑过使用 Redis 数据集配置 而不是编写自定义代码?
Maybe you should call JedisPool.returnBrokenResource() somewhere in finally block and catching more specific exception?
you can also consider using Jedis.close() instead.
By the way, have you considered using Redis Data Set Config instead of writing the custom code?