Project online environment discovery: java.util.nosuchelementexception: timeout waiting for idle object
Cause of the problem: instead of releasing resources in try, it should be handled in finally. Although it is a very basic grammar, it may be wrongly written. When maintaining the old system, we find that there are many potential bugs, so we should take a warning. To release resources in try, every time an exception occurs, a jedis object will not be released, and the available jedis object resources in pool will be less and less, which will eventually lead to java.util.nosuchelementexception: timeout waiting for idle object. This kind of problem is a chronic problem, it takes time to accumulate
Because the request can’t get the free object, the page will appear server 500 error. If the code is added to the loop to get jedis, the server may also be down
try {
jedis = pool.getResource();
// xxx business code
// original code: pool.returnResource(jedis);, should be placed in the finally block, otherwise each time an exception occurs will result in a jedis object not being t
} catch (RuntimeException e) {
if(jedis ! = null ) {
pool.returnBrokenResource(jedis);
}
} finally{
// Release the resource correctly
if(jedis ! = null ) {
pool.returnResource(jedis);
}
}
Similar Posts:
- Redis uses connection pool to solve the problem of error reporting
- How to Solve Jedis Error: java.lang.ClassCastException: java.lang.Long cannot be cast to [B
- [Solved] Redis has java.net.socketexception: permission denied: connect problem during stress test
- Mysql Cannot get a connection, pool error Timeout waiting for idle object
- [Solved] Redis Operation exception: java.lang.ClassCastException: java.lang.Long cannot be cast to [B
- [Solved] reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response
- [Solved] Jedis:Exception in thread “main” java.lang.VerifyError: Bad type on operand stack
- [Solved] ConnectionPoolTimeoutException: Timeout waiting for connection from pool
- How to Solve Error: Scanner class java. Util. NoSuchElementException exception
- [Solved] SpringBoot Access Redis Error: java.lang.NoSuchMethodError: redis.clients.jedis.JedisPoolConfig.setMinEvictableIdleTime