JedisPoolConfig 参数的使用 *blockWhenExhausted*

Sul*_*eyo 3 java apache-commons redis jedis spring-data-redis

所以我有一个项目,我使用Spring-Data-Redis来缓存一些数据。该Spring-Data-Redis是用bean的配置设置与Jedis。

我寻找JedisPoolConfig可以修改的参数来控制我的缓存和应用程序的行为。

我想知道属性的用途,blockWhenExhausted,它是可配置属性的一部分。据说默认值是true,这个默认值会调用什么行为?如果将该值更改为false,这将带来什么行为?

Laz*_*ass 5

该值改变了GenericObjectPool.borrowObject(longborrowMaxWaitMillis)的行为

使用特定的等待时间从池中借用对象,该等待时间仅适用于 BaseGenericObjectPool.getBlockWhenExhausted() 为 true 的情况。

这意味着当您设置blockWhenExhaustedfalse指定的时间时,borrowMaxWaitMillis将不会使用并且borrowObject调用将阻塞,直到池中有空闲的 jedis 连接可用。

如果池耗尽(没有可用的空闲实例并且没有能力创建新实例),此方法将阻塞(如果 BaseGenericObjectPool.getBlockWhenExhausted() 为真)或抛出 NoSuchElementException(如果 BaseGenericObjectPool.getBlockWhenExhausted() 为假)

有趣的是,我看不到JedisPool实现实际上正在使用该borrowObject(long borrowMaxWaitMillis)方法。我只能看到borrowObject(没有参数) 在getResource (in the version 3.0.0-SNAPSHOT)期间被调用。所以我不确定所描述的行为是否也适用于 JedisPool。