有关 C3P0 池数据源的问题
我尝试使用池数据源来记录有关数据库连接池的信息,即最大池大小、当前数量。正在使用的连接数、繁忙连接等。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试阅读 PooledDataSource java doc。 http://www.mchange.com/projects /c3p0/apidocs/com/mchange/v2/c3p0/PooledDataSource.html
PooledDataSource.getXXXXUser() 是监视和管理数据源的正确方法
仅当
出于管理原因您希望密切跟踪
您的应用程序正在使用的所有连接的数量和状态;
解决在管理数据源时遇到的问题,该数据源的客户端是编码不良的应用程序,会泄漏连接,但您无权修复这些问题;
另外javadoc 中提供了有关方法名称的描述。
请参阅“方法名称...”部分
此接口中的许多方法具有三种变体:
第一个变体使用为默认用户维护的池——通过调用无参数 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
for administrative reasons you like to keep close track of the
number and status of all Connections your application is using;
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;
also There is description on method names available in javadoc.
see Method Names ... section
Many methods in this interface have three variants:
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.