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
source share