警告 rcjJedisFactory:关闭 redis.clients.jedis.exceptions.JedisException 时出错:无法将损坏的资源返回到池中

发布于 2025-01-10 11:32:43 字数 1762 浏览 0 评论 0原文

我收到以下错误

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独闯女儿国 2025-01-17 11:32:43

也许你应该打电话 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文