3

So I have a project where I'm using the Spring-Data-Redis to cache some data. The Spring-Data-Redis is setup with Jedis using Bean Configuration.

I looked for the JedisPoolConfig parameters that can be modified to control the behavior of my Caching and App.

I will like to know the use of the property, blockWhenExhausted, which is part of the configurable properties. The default value is said to be true, what behaviour will this default value invoke? If the value is changed to false, what behaviour will this bring it?

Sulaiman Adeeyo
  • 485
  • 6
  • 19

1 Answers1

5

The value changes the behavior of GenericObjectPool.borrowObject(long borrowMaxWaitMillis)

Borrow an object from the pool using the specific waiting time which only applies if BaseGenericObjectPool.getBlockWhenExhausted() is true.

Which means when you set blockWhenExhausted to false the time specified with borrowMaxWaitMillis will not be used and the borrowObject call will block until there is an idle jedis connection from the pool available.

If the pool is exhausted (no available idle instances and no capacity to create new ones), this method will either block (if BaseGenericObjectPool.getBlockWhenExhausted() is true) or throw a NoSuchElementException (if BaseGenericObjectPool.getBlockWhenExhausted() is false)

But interestingly I could not see that the JedisPool implementation is actually using the borrowObject(long borrowMaxWaitMillis) method. I could only see that borrowObject (without parameter) is called during getResource (in the version 3.0.0-SNAPSHOT) . So i'm not sure if the described behavior also applies for JedisPool.

brass monkey
  • 5,841
  • 10
  • 36
  • 61
  • The method without the parameter is implemented as: public T borrowObject() throws Exception { return borrowObject(getMaxWaitDuration()); } – Bryan Bende Oct 24 '22 at 15:51