Consolidated C3P0 Data Source Questions

I tried to use the Pooled Data source to log database connection pool information. i. Max. pool size, current number. connections used, busy connections, etc. I am using C3P0Registry to get the data pool.

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 log the 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 what if this is the right way to achieve my goal ?.
Plus, I have confusion about the fact that dataSource.getNumConnectionsAllUsers () and the other function (I use) exactly return. There is no description in javadoc.

Is there any description or maybe a tutorial is available online, how can I find out more about these specific functions?

Environment : Java, Hibernate, C3P0, MySQL

+4
source share
1 answer

try reading the java document PooledDataSource. http://www.mchange.com/projects/c3p0/apidocs/com/mchange/v2/c3p0/PooledDataSource.html

PooledDataSource.getXXXXUser () is the right way to monitor and manage your data source.

The functionality of this interface will be interesting only if

  • for administrative reasons, you like to closely monitor the number and status of all connections that your application uses;

  • to get around the problems that arise when managing a DataSource, whose clients are poorly encoded applications that leak Connections, but which you are not allowed to fix;

  • to fix problems that may arise if the underlying jdbc / DBMS system is unreliable ..

Also javadoc is available in method names.

see the section "Method Names" ... section

Many methods in this interface have three options:

  • <method-name> DefaultUser ()
  • <method-name> (username String, password String)
  • <method-name> AllUsers ()

The first option uses a pool that is supported for the user by default. Connections created by calls without the getConnection () argument, the second option allows you to monitor pools created by calling getConnection (username, password), and the third option provides aggregate information or performs operations in all pools.

+2
source

All Articles