java - JedisPoolConfig 参数 *blockWhenExhausted* 的使用

标签 java redis apache-commons jedis spring-data-redis

所以我有一个项目,我在其中使用 Spring-Data-Redis 来缓存一些数据。 Spring-Data-Redis 使用 Bean 配置与 Jedis 一起设置。

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

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

最佳答案

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

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

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

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)

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

关于java - JedisPoolConfig 参数 *blockWhenExhausted* 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38354520/

相关文章:

java - 有没有办法用guice注入(inject)最后一个类?

database - 易于使用/嵌入二进制安全的键/值数据库

java - 如果你想访问encodeHexString等,你在哪里添加 'commons-codec-1.4.jar'?

java - 为什么 Maven 版本会跳过我的子模块

java - 启动时自动点击器 UI 变黑

python - Redis、Python 通过网络发送消息

java - Apache commons fileupload FileItemIterator hasNext() 返回 false

java - Apache Lang3 StopWatch.split()的意义是什么?

java - Spring的Singleton作用域bean在Web应用程序中的表现如何?

redis - 使用 Beanshell 将 Jmeter 连接到 Redis