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);
}
}