Interface PooledDataSource

All Superinterfaces:
CommonDataSource, DataSource, Wrapper
All Known Implementing Classes:
AbstractComboPooledDataSource, AbstractPoolBackedDataSource, AfterCloseLoggingComboPooledDataSource, CloseLoggingComboPooledDataSource, ComboPooledDataSource, ConstructionLoggingComboPooledDataSource, PoolBackedDataSource

public interface PooledDataSource extends DataSource

Most clients need never use or know about this interface -- c3p0 pooled DataSources can be treated like any other DataSource.

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; or 3) to work around problems that may occur if an underlying jdbc driver / DBMS system is unreliable. In the third case, most users will be better off not using the present interface at all, and using the DataSources' maxIdleTime, idleConnectionTestPeriod, or testConnectionOnCheckout parameters to help your DataSources "automatically" heal. But for those who prefer a more direct, manual approach, this interface is for you. It is anticipated that the methods of this interface will primarily be of use to administrators managing c3p0 PooledDataSources via JMX MBeans.

Method Names invalid input: '&' Per-User Pools

To understand this interface, you need to realize that a c3p0 PooledDataSource may represent not just one pool of Connections, but many, if users call the method Connection getConnection(String username, String password) rather than the no-argument getConnection() method. If users make use of non-default username, password combinations, there will be a separate pool for each set of authentification criteria supplied.

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.

Under most circumstances, non-default authentication credentials will not be used, and methods of the first variant are sufficient to manage the DataSource.

Soft and Hard Resets

A properly configured PooledDataSource whose applications are careful to close all checked-out Connections would never need to use these methods. But, sometimes applications are untrustworthy and leak Connections, or database administrators suspect that Connections may be corrupt or invalid, and would like to force a pool to flush and acquire fresh Connections. This interface provides two ways to do so.

  1. hardReset() immediately closes all Connections managed by the DataSource, including those that are currently checked out, bringing the DataSource back to the state it was in before the first client called getConnection(). This method is obviously disruptive, and should be with great care. Administrators who need to work around client applications that leak Connections, can periodically poll for pool exhaustion (using the methods of this class, or by attempting to retrieve a Connection and timing out) and use this method clean-up all Connections and start over. But calling this method risks breaking Connections in current use by valid applications.

  2. softResetDefaultUser(), softReset( username, password ) and softResetAllUsers() asks the DataSource to flush its current pool of Connections and reacquire without invalidating currently checked-out Connections. Currently checked out Connections are logically removed from the pool, but their destruction is deferred until a client attempts to close() / check-in the Connection. Administrators who suspect that some Connections in the pool may be invalid, but who do not wish to rely upon c3p0's automatic testing and detection mechanisms to resolve the problem, may call these methods to force a refresh without disrupting current clients. Administrators who suspect that clients may be leaking Connections may minimize disruptive hardReset() calls by using softReset() until the number of unclosed orphaned connections reaches an unacceptable level. (See above to understand why there are three variants of this method.)

Understanding Connection Counts

For each per-user pool, four different statistics are available:

  1. numConnections represents the total number of Connections in the pool.

  2. numIdleConnections represents the number of Connections in the pool that are currently available for checkout.

  3. numBusyConnections represents the number of Connections in the pool that are currently checked out. The invariant numIdleConnections + numBusyConnections == numConnections should always hold.

  4. numUnclosedOrphanedConnections will only be non-zero following a call to softReset(). It represents the number of Connections that were checked out when a soft reset occurred and were therefore silently excluded from the pool, and which remain unclosed by the client application.
  • Method Details

    • getIdentityToken

      String getIdentityToken()
    • getDataSourceName

      String getDataSourceName()
    • setDataSourceName

      void setDataSourceName(String dataSourceName)
    • getExtensions

      Map getExtensions()
    • setExtensions

      void setExtensions(Map extensions)
    • getNumConnections

      int getNumConnections() throws SQLException
      Deprecated.
      use getNumConnectionsDefaultUser()
      Throws:
      SQLException
    • getNumIdleConnections

      int getNumIdleConnections() throws SQLException
      Deprecated.
      use getNumIdleConnectionsDefaultUser()
      Throws:
      SQLException
    • getNumBusyConnections

      int getNumBusyConnections() throws SQLException
      Deprecated.
      use getNumBusyConnectionsDefaultUser()
      Throws:
      SQLException
    • getNumUnclosedOrphanedConnections

      int getNumUnclosedOrphanedConnections() throws SQLException
      Deprecated.
      use getNumUnclosedOrphanedConnectionsDefaultUser()
      Throws:
      SQLException
    • getNumConnectionsDefaultUser

      int getNumConnectionsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getNumIdleConnectionsDefaultUser

      int getNumIdleConnectionsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getNumBusyConnectionsDefaultUser

      int getNumBusyConnectionsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getNumUnclosedOrphanedConnectionsDefaultUser

      int getNumUnclosedOrphanedConnectionsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumStatementsDefaultUser

      int getStatementCacheNumStatementsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumCheckedOutDefaultUser

      int getStatementCacheNumCheckedOutDefaultUser() throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumConnectionsWithCachedStatementsDefaultUser

      int getStatementCacheNumConnectionsWithCachedStatementsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getStartTimeMillisDefaultUser

      long getStartTimeMillisDefaultUser() throws SQLException
      Throws:
      SQLException
    • getUpTimeMillisDefaultUser

      long getUpTimeMillisDefaultUser() throws SQLException
      Throws:
      SQLException
    • getNumFailedCheckinsDefaultUser

      long getNumFailedCheckinsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getNumFailedCheckoutsDefaultUser

      long getNumFailedCheckoutsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getNumFailedIdleTestsDefaultUser

      long getNumFailedIdleTestsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getEffectivePropertyCycleDefaultUser

      float getEffectivePropertyCycleDefaultUser() throws SQLException
      Throws:
      SQLException
    • getNumThreadsAwaitingCheckoutDefaultUser

      int getNumThreadsAwaitingCheckoutDefaultUser() throws SQLException
      Throws:
      SQLException
    • softResetDefaultUser

      void softResetDefaultUser() throws SQLException
      Discards all Connections managed by the PooledDataSource's default-authentication pool and reacquires new Connections to populate. Current checked out Connections will still be valid, and should still be checked into the PooledDataSource (so the PooledDataSource can destroy them).
      Throws:
      SQLException
    • getNumConnections

      int getNumConnections(String username, String password) throws SQLException
      Throws:
      SQLException
    • getNumIdleConnections

      int getNumIdleConnections(String username, String password) throws SQLException
      Throws:
      SQLException
    • getNumBusyConnections

      int getNumBusyConnections(String username, String password) throws SQLException
      Throws:
      SQLException
    • getNumUnclosedOrphanedConnections

      int getNumUnclosedOrphanedConnections(String username, String password) throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumStatements

      int getStatementCacheNumStatements(String username, String password) throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumCheckedOut

      int getStatementCacheNumCheckedOut(String username, String password) throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumConnectionsWithCachedStatements

      int getStatementCacheNumConnectionsWithCachedStatements(String username, String password) throws SQLException
      Throws:
      SQLException
    • getEffectivePropertyCycle

      float getEffectivePropertyCycle(String username, String password) throws SQLException
      Throws:
      SQLException
    • getNumThreadsAwaitingCheckout

      int getNumThreadsAwaitingCheckout(String username, String password) throws SQLException
      Throws:
      SQLException
    • softReset

      void softReset(String username, String password) throws SQLException
      Discards all Connections managed by the PooledDataSource with the specified authentication credentials and reacquires new Connections to populate. Current checked out Connections will still be valid, and should still be checked into the PooledDataSource (so the PooledDataSource can destroy them).
      Throws:
      SQLException
    • getNumBusyConnectionsAllUsers

      int getNumBusyConnectionsAllUsers() throws SQLException
      Throws:
      SQLException
    • getNumIdleConnectionsAllUsers

      int getNumIdleConnectionsAllUsers() throws SQLException
      Throws:
      SQLException
    • getNumConnectionsAllUsers

      int getNumConnectionsAllUsers() throws SQLException
      Throws:
      SQLException
    • getNumUnclosedOrphanedConnectionsAllUsers

      int getNumUnclosedOrphanedConnectionsAllUsers() throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumStatementsAllUsers

      int getStatementCacheNumStatementsAllUsers() throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumCheckedOutStatementsAllUsers

      int getStatementCacheNumCheckedOutStatementsAllUsers() throws SQLException
      Throws:
      SQLException
    • getStatementCacheNumConnectionsWithCachedStatementsAllUsers

      int getStatementCacheNumConnectionsWithCachedStatementsAllUsers() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumConnectionsInUseAllUsers

      int getStatementDestroyerNumConnectionsInUseAllUsers() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumConnectionsWithDeferredDestroyStatementsAllUsers

      int getStatementDestroyerNumConnectionsWithDeferredDestroyStatementsAllUsers() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumDeferredDestroyStatementsAllUsers

      int getStatementDestroyerNumDeferredDestroyStatementsAllUsers() throws SQLException
      Throws:
      SQLException
    • getThreadPoolSize

      int getThreadPoolSize() throws SQLException
      Throws:
      SQLException
    • getThreadPoolNumActiveThreads

      int getThreadPoolNumActiveThreads() throws SQLException
      Throws:
      SQLException
    • getThreadPoolNumIdleThreads

      int getThreadPoolNumIdleThreads() throws SQLException
      Throws:
      SQLException
    • getThreadPoolNumTasksPending

      int getThreadPoolNumTasksPending() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumThreads

      int getStatementDestroyerNumThreads() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumActiveThreads

      int getStatementDestroyerNumActiveThreads() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumIdleThreads

      int getStatementDestroyerNumIdleThreads() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumTasksPending

      int getStatementDestroyerNumTasksPending() throws SQLException
      Throws:
      SQLException
    • sampleThreadPoolStackTraces

      String sampleThreadPoolStackTraces() throws SQLException
      Throws:
      SQLException
    • sampleThreadPoolStatus

      String sampleThreadPoolStatus() throws SQLException
      Throws:
      SQLException
    • sampleStatementDestroyerStackTraces

      String sampleStatementDestroyerStackTraces() throws SQLException
      Throws:
      SQLException
    • sampleStatementDestroyerStatus

      String sampleStatementDestroyerStatus() throws SQLException
      Throws:
      SQLException
    • sampleStatementCacheStatusDefaultUser

      String sampleStatementCacheStatusDefaultUser() throws SQLException
      Throws:
      SQLException
    • sampleStatementCacheStatus

      String sampleStatementCacheStatus(String username, String password) throws SQLException
      Throws:
      SQLException
    • getLastAcquisitionFailureDefaultUser

      Throwable getLastAcquisitionFailureDefaultUser() throws SQLException
      Throws:
      SQLException
    • getLastCheckinFailureDefaultUser

      Throwable getLastCheckinFailureDefaultUser() throws SQLException
      Throws:
      SQLException
    • getLastCheckoutFailureDefaultUser

      Throwable getLastCheckoutFailureDefaultUser() throws SQLException
      Throws:
      SQLException
    • getLastIdleTestFailureDefaultUser

      Throwable getLastIdleTestFailureDefaultUser() throws SQLException
      Throws:
      SQLException
    • getLastConnectionTestFailureDefaultUser

      Throwable getLastConnectionTestFailureDefaultUser() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumConnectionsInUseDefaultUser

      int getStatementDestroyerNumConnectionsInUseDefaultUser() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumConnectionsWithDeferredDestroyStatementsDefaultUser

      int getStatementDestroyerNumConnectionsWithDeferredDestroyStatementsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumDeferredDestroyStatementsDefaultUser

      int getStatementDestroyerNumDeferredDestroyStatementsDefaultUser() throws SQLException
      Throws:
      SQLException
    • getLastAcquisitionFailure

      Throwable getLastAcquisitionFailure(String username, String password) throws SQLException
      Throws:
      SQLException
    • getLastCheckinFailure

      Throwable getLastCheckinFailure(String username, String password) throws SQLException
      Throws:
      SQLException
    • getLastCheckoutFailure

      Throwable getLastCheckoutFailure(String username, String password) throws SQLException
      Throws:
      SQLException
    • getLastIdleTestFailure

      Throwable getLastIdleTestFailure(String username, String password) throws SQLException
      Throws:
      SQLException
    • getLastConnectionTestFailure

      Throwable getLastConnectionTestFailure(String username, String password) throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumConnectionsInUse

      int getStatementDestroyerNumConnectionsInUse(String username, String password) throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumConnectionsWithDeferredDestroyStatements

      int getStatementDestroyerNumConnectionsWithDeferredDestroyStatements(String username, String password) throws SQLException
      Throws:
      SQLException
    • getStatementDestroyerNumDeferredDestroyStatements

      int getStatementDestroyerNumDeferredDestroyStatements(String username, String password) throws SQLException
      Throws:
      SQLException
    • sampleLastAcquisitionFailureStackTraceDefaultUser

      String sampleLastAcquisitionFailureStackTraceDefaultUser() throws SQLException
      Throws:
      SQLException
    • sampleLastCheckinFailureStackTraceDefaultUser

      String sampleLastCheckinFailureStackTraceDefaultUser() throws SQLException
      Throws:
      SQLException
    • sampleLastCheckoutFailureStackTraceDefaultUser

      String sampleLastCheckoutFailureStackTraceDefaultUser() throws SQLException
      Throws:
      SQLException
    • sampleLastIdleTestFailureStackTraceDefaultUser

      String sampleLastIdleTestFailureStackTraceDefaultUser() throws SQLException
      Throws:
      SQLException
    • sampleLastConnectionTestFailureStackTraceDefaultUser

      String sampleLastConnectionTestFailureStackTraceDefaultUser() throws SQLException
      Throws:
      SQLException
    • sampleLastAcquisitionFailureStackTrace

      String sampleLastAcquisitionFailureStackTrace(String username, String password) throws SQLException
      Throws:
      SQLException
    • sampleLastCheckinFailureStackTrace

      String sampleLastCheckinFailureStackTrace(String username, String password) throws SQLException
      Throws:
      SQLException
    • sampleLastCheckoutFailureStackTrace

      String sampleLastCheckoutFailureStackTrace(String username, String password) throws SQLException
      Throws:
      SQLException
    • sampleLastIdleTestFailureStackTrace

      String sampleLastIdleTestFailureStackTrace(String username, String password) throws SQLException
      Throws:
      SQLException
    • sampleLastConnectionTestFailureStackTrace

      String sampleLastConnectionTestFailureStackTrace(String username, String password) throws SQLException
      Throws:
      SQLException
    • softResetAllUsers

      void softResetAllUsers() throws SQLException
      Discards all Connections managed by the PooledDataSource and reacquires new Connections to populate. Current checked out Connections will still be valid, and should still be checked into the PooledDataSource (so the PooledDataSource can destroy them).
      Throws:
      SQLException
    • getNumUserPools

      int getNumUserPools() throws SQLException
      Throws:
      SQLException
    • getNumHelperThreads

      int getNumHelperThreads() throws SQLException
      Throws:
      SQLException
    • getAllUsers

      Collection getAllUsers() throws SQLException
      Throws:
      SQLException
    • hardReset

      void hardReset() throws SQLException
      Destroys all pooled and checked-out Connections associated with this DataSource immediately. The PooledDataSource is reset to its initial state prior to first Connection acquisition, with no pools yet active, but ready for requests.
      Throws:
      SQLException
    • close

      void close() throws SQLException

      C3P0 pooled DataSources use no resources before they are actually used in a VM, and they close themselves in their finalize() method. When they are active and pooling, they may have open database connections and their pool may spawn several threads for its maintenance. You can use this method to clean these resource methods up quickly when you will no longer be using this DataSource. The resources will actually be cleaned up only if no other DataSources are sharing the same pool.

      You can equivalently use the static method destroy() in the DataSources class to clean-up these resources.

      This is equivalent to calling close( false ).

      Throws:
      SQLException
      See Also:
    • close

      void close(boolean force_destory) throws SQLException
      Deprecated.
      the force_destroy argument is now meaningless, as pools are no longer potentially shared between multiple DataSources.

      Should be used only with great caution. If force_destroy is set to true, this immediately destroys any pool and cleans up all resources this DataSource may be using, even if other DataSources are sharing that pool! In general, it is difficult to know whether a pool is being shared by multiple DataSources. It may depend upon whether or not a JNDI implementation returns a single instance or multiple copies upon lookup (which is undefined by the JNDI spec).

      In general, this method should be used only when you wish to wind down all c3p0 pools in a ClassLoader. For example, when shutting down and restarting a web application that uses c3p0, you may wish to kill all threads making use of classes loaded by a web-app specific ClassLoader, so that the ClassLoader can be cleanly garbage collected. In this case, you may wish to use force destroy. Otherwise, it is much safer to use the simple destroy() method, which will not shut down pools that may still be in use.

      To close a pool normally, use the no argument close method, or set force_destroy to false.

      Throws:
      SQLException
      See Also: