title: Jedis is running out of resource instances, web application blocks
body: <p>I'm running a Tomcat application which uses Jedis to access a Redis database. Form time to time the whole application blocks. By monitoring Tomcat using JavaMelody I found out that the problem seems be related to the JedisPool when a object requests a Jedis instance.</p>
  
  <pre><code>catalina-exec-74
  java.lang.Object.wait(Native&amp;nbsp;Method)
  java.lang.Object.wait(Object.java:503)
  org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1104)
  redis.clients.util.Pool.getResource(Pool.java:20)
  ....
  </code></pre>
  
  <p>This is the JedisPoolConfig I'm using </p>
  
  <pre><code>JedisPoolConfig poolConfig = new JedisPoolConfig();
  poolConfig.setMaxActive(20);
  poolConfig.setTestOnBorrow(true);
  poolConfig.setTestOnReturn(true);
  poolConfig.setMaxIdle(5);
  poolConfig.setMinIdle(5);
  poolConfig.setTestWhileIdle(true);
  poolConfig.setNumTestsPerEvictionRun(10);
  poolConfig.setTimeBetweenEvictionRunsMillis(10000);
  jedisPool = new JedisPool(poolConfig, "localhost");
  </code></pre>
  
  <p>So obviously some threads try to get a Jedis instance but the pool is empty and cannot return an instance so the default pool behavior is wait. </p>
  
  <p>I've already double checked my whole code and I'm pretty sure I return every Jedis instance to the pool that I used before. So I'm not sure why I'm running out of instance. </p>
  
  <p>Is there a ways to check how many instances are left in the pool? I'm trying to find a sensible value for the maxActive parameter to prevent the application from blocking. </p>
  
  <p>Are there any other ways to create memory holes other than not returning the Jedis instances to the pool? </p>