Class MiniConnectionPoolManager

java.lang.Object
ca.phon.ipadictionary.impl.MiniConnectionPoolManager

public class MiniConnectionPoolManager extends Object
A simple standalone JDBC connection pool manager.

The public methods of this class are thread-safe.

Author: Christian d'Heureuse (www.source-code.biz)
Multi-licensed: EPL/LGPL/MPL.

2007-06-21: Constructor with a timeout parameter added.
2008-05-03: Additional licenses added (EPL/MPL).

  • Constructor Details

    • MiniConnectionPoolManager

      public MiniConnectionPoolManager(ConnectionPoolDataSource dataSource, int maxConnections)
      Constructs a MiniConnectionPoolManager object with a timeout of 60 seconds.
      Parameters:
      dataSource - the data source for the connections.
      maxConnections - the maximum number of connections.
    • MiniConnectionPoolManager

      public MiniConnectionPoolManager(ConnectionPoolDataSource dataSource, int maxConnections, int timeout)
      Constructs a MiniConnectionPoolManager object.
      Parameters:
      dataSource - the data source for the connections.
      maxConnections - the maximum number of connections.
      timeout - the maximum time in seconds to wait for a free connection.
  • Method Details

    • dispose

      public void dispose() throws SQLException
      Closes all unused pooled connections.
      Throws:
      SQLException
    • getConnection

      public Connection getConnection() throws SQLException
      Retrieves a connection from the connection pool. If maxConnections connections are already in use, the method waits until a connection becomes available or timeout seconds elapsed. When the application is finished using the connection, it must close it in order to return it to the pool.
      Returns:
      a new Connection object.
      Throws:
      MiniConnectionPoolManager.TimeoutException - when no connection becomes available within timeout seconds.
      SQLException
    • getActiveConnections

      public int getActiveConnections()
      Returns the number of active (open) connections of this pool. This is the number of Connection objects that have been issued by getConnection() for which Connection.close() has not yet been called.
      Returns:
      the number of active connections.