Apache Commons Pool 2 中的 maxTotal 和 maxIdle 有什么区别? [英] What is the difference between maxTotal and maxIdle in Apache Commons Pool 2?

查看:27
本文介绍了Apache Commons Pool 2 中的 maxTotal 和 maxIdle 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache Commons Pool 2 实现来为我的应用程序提供对象池机制.

I'm using the Apache Commons Pool 2 implementation to have object pool mechanism for my application.

截至目前,我已在我的代码中将 maxTotal()maxIdle() 的默认值设置为 10.

As of now, I have set the default value of maxTotal() and maxIdle() as 10 in my code.

但我无法理解它们之间的区别是什么?如果我将 maxIdle() 设置为一个非常小(假设为 0)或非常大(等于 maxTotal())的值会怎样?

But I am not able to understand what is the difference between them ? What if I set the maxIdle() as a value very small (let's say 0) or very large (equal to maxTotal()) ?

注意:Apache 类在内部为上述两个配置推荐默认值 8.

Note: Apache classes internally recommends a default value of 8 to both of the above configs.

推荐答案

连接池是一种技术,用于与不受限制的并发用户数共享有限数量的数据库连接.最大连接总数 (maxTotal) 包括活动连接和空闲连接,即正在使用的连接和当前未使用的连接(它是所有连接的总和).最大空闲连接数 (maxIdle) 是准备使用(但当前未使用)的连接.如果您将 maxTotal 设置为 100,那么一次最多将打开 100 个连接到您的数据库,如果 maxIdle 设置为 10,那么如果没有连接最多可以释放 90 个连接.池将按需重新连接.

A connection pool is a technique for sharing a limited number of database connections with an unconstrained number of simultaneous users. The maximum total connections (maxTotal) includes both active and idle connections, that is connections being used and connections not currently being used (it is the sum total of all connections). The maximum idle connections (maxIdle) are connections that are ready to be used (but are currently unused). If you set the maxTotal to 100 then a maximum 100 connections will be opened to your database at one time, if the maxIdle were set to 10 then if none of the connections are being used up to 90 connections might be released. The pool will re-connect on demand.

在池中,空闲连接已准备就绪,如果连接当前处于空闲状态(池返回空闲连接),则不会阻止连接请求.如果没有连接空闲,则池将阻塞以打开连接或直到连接返回到池中.

In a pool, the idle connections are ready and a request for a connection will not block if a connection is currently idle (the pool returns the idle connection). If no connections are idle, then the pool will block to open a connection or until a connection is returned to the pool.

在您的问题中,两者的最大值为 10,将打开 10 个连接并且池不会缩小或增长.

In your question, with 10 for the maximum of both, ten Connection(s) will be opened and the pool will not shrink or grow.

这篇关于Apache Commons Pool 2 中的 maxTotal 和 maxIdle 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆