有关 C3P0 池数据源的问题

发布于 2024-12-06 11:24:26 字数 1271 浏览 1 评论 0原文

我尝试使用池数据源来记录有关数据库连接池的信息,即最大池大小、当前数量。正在使用的连接数、繁忙连接等。我正在使用 C3P0Registry 来获取汇总数据源。

PooledDataSource dataSource =null;
    try{
        C3P0Registry.getNumPooledDataSources();
        //I am sure that I am using only one data source
        Iterator<Set> connectionIterator = C3P0Registry.getPooledDataSources().iterator();
        dataSource = (PooledDataSource)connectionIterator.next();
    }catch (Exception e) {
    }

然后我将所需信息记录为:

Logger.write(LoggerConstant.DEBUG, " Connections in use: "+dataSource.getNumConnectionsAllUsers()+" , Busy Connections: "+dataSource.getNumBusyConnectionsAllUsers() +" , Idle Connections: "+ dataSource.getNumIdleConnectionsAllUsers()+" , Unclosed Orphaned Connections: "+ dataSource.getNumUnclosedOrphanedConnectionsAllUsers(), methodName);

我想知道这是否是实现我的目标的正确方法?。
另外,我对 是什么感到困惑dataSource.getNumConnectionsAllUsers() 和其他函数(我正在使用)完全返回。 javadoc 中没有可用的描述。

是否有任何描述或在线教程可以让我了解有关这些特定功能的更多信息?

环境:Java、Hibernate、C3P0、MySQL

I tried to use Pooled Data source to log information regarding database connection pool i.e, Max pool size, current no. of connections in use, busy connection etc. I am using C3P0Registry to get pooled data source.

PooledDataSource dataSource =null;
    try{
        C3P0Registry.getNumPooledDataSources();
        //I am sure that I am using only one data source
        Iterator<Set> connectionIterator = C3P0Registry.getPooledDataSources().iterator();
        dataSource = (PooledDataSource)connectionIterator.next();
    }catch (Exception e) {
    }

and then i am logging required information as:

Logger.write(LoggerConstant.DEBUG, " Connections in use: "+dataSource.getNumConnectionsAllUsers()+" , Busy Connections: "+dataSource.getNumBusyConnectionsAllUsers() +" , Idle Connections: "+ dataSource.getNumIdleConnectionsAllUsers()+" , Unclosed Orphaned Connections: "+ dataSource.getNumUnclosedOrphanedConnectionsAllUsers(), methodName);

I want to know that if its a correct way to achieve my goal?.

Plus i am having confusions regarding What does dataSource.getNumConnectionsAllUsers() and other function (i am using) exactly return. There is no description available in javadoc.

Is there any description or may be tutorial available online from where i can learn more about these particular functions?

Environment: Java, Hibernate, C3P0, MySQL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千寻… 2024-12-13 11:24:26

尝试阅读 PooledDataSource java doc。 http://www.mchange.com/projects /c3p0/apidocs/com/mchange/v2/c3p0/PooledDataSource.html

PooledDataSource.getXXXXUser() 是监视和管理数据源的正确方法

仅当

  1. 出于管理原因您希望密切跟踪
    您的应用程序正在使用的所有连接的数量和状态;

  2. 解决在管理数据源时遇到的问题,该数据源的客户端是编码不良的应用程序,会泄漏连接,但您无权修复这些问题;

  3. 解决底层 jdbc 驱动程序/DBMS 系统不可靠时可能出现的问题。 。

另外javadoc 中提供了有关方法名称的描述。

请参阅“方法名称...”部分

此接口中的许多方法具有三种变体:

  1. 方法名称>默认用户()
  2. <方法名称> (字符串用户名,字符串密码)
  3. <方法名称> AllUsers()

第一个变体使用为默认用户维护的池——通过调用无参数 getConnection() 创建的连接,第二个变体允许您跟踪通过调用 getConnection( username, password ) 创建的池,以及第三种变体提供聚合信息或对所有池执行操作。

try read PooledDataSource java doc. http://www.mchange.com/projects/c3p0/apidocs/com/mchange/v2/c3p0/PooledDataSource.html

PooledDataSource.getXXXXUser() is correct way of monitor and manage data source

The functionality in this interface will be only be of interest if

  1. for administrative reasons you like to keep close track of the
    number and status of all Connections your application is using;

  2. to work around problems encountered while managing a DataSource whose clients are poorly coded applications that leak Connections, but which you are not permitted to fix;

  3. to work around problems that may occur if an underlying jdbc driver / DBMS system is unreliable. .

also There is description on method names available in javadoc.

see Method Names ... section

Many methods in this interface have three variants:

  1. < method-name> DefaultUser()
  2. < method-name> (String username, String password)
  3. < method-name> AllUsers()

The first variant makes use of the pool maintained for the default user -- Connections created by calls to the no argument getConnection(), the second variant lets you keeps track of pools created by calling getConnection( username, password ), and the third variant provides aggregate information or performs operation on all pools.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文