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

查看:2754
本文介绍了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个连接两个,将打开十个连接,池不会缩小或增长。

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天全站免登陆