如果禁用 blockWhenExhausted,CommonsPool2TargetSource 会做什么?

What does CommonsPool2TargetSource do if you disable blockWhenExhausted?

已弃用的 CommonPoolTargetSource 有一组行为,您可以使用 setWhenExhaustedActionName(). The CommonsPool2TargetSource and the CommonsPool2 BaseGenericObjectPool 将其包装 describe "getBlockWhenExhausted" 定义为

Returns whether to block when the borrowObject() method is invoked when the pool is exhausted

我想通了!否则这有什么作用?

当您将 CommonsPool 设置为 "WHEN_EXHAUSTED_GROW" 时,Pool 会得到扩展还是只是抛出异常?会发生什么?

ObjectPool.borrowObject() 文档中所述,耗尽时的行为取决于实现。

The behaviour of this method when the pool has been exhausted is not strictly specified (although it may be specified by implementations).

CommonsPool2 提供的 GenericObjectPool 实现将在 getBlockWhenExhausted() 为真时阻塞,否则立即抛出 NoSuchElementException。 (如 GenericObjectPoolborrowObject(long borrowMaxWaitMillis) 中所述)

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). The length of time that this method will block when BaseGenericObjectPool.getBlockWhenExhausted() is true is determined by the value passed in to the borrowMaxWaitMillis parameter.

与 "WHEN_EXHAUSTED_GROW" 类似的行为不可用,最有可能通过将 maxTotal 设置为 -1 来实现,因此池根本不会耗尽​​。