    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class com.bitmechanic.sql.ConnectionPool

    com.bitmechanic.sql.ConnectionPool

public class ConnectionPool

Individual pool associated with a JDBC datasource and username. Each pool is identified by an alias. Use the alias name to acquire a ref to a Connection from the pool. See the ConnectionPoolManager for further details on how to do this.

Version:
  $Id: ConnectionPool.java,v 1.11 1998/12/16 01:15:22 pixel Exp $
Author:
  James Cooper
See Also:
  ConnectionPoolManager

##

ConnectionPool(String, String, String, String, int, int, int)
  Creates a Connection pool with no maxCheckout parameter.
ConnectionPool(String, String, String, String, int, int, int, int)
  Creates a Connection pool

##

getAlias()
  Returns the alias for this pool.
getConnection()
  Returns a connection for the pool.
getMaxConn()
  Returns the maximum number of connections this pool can open
getNumCheckoutTimeouts()
  Returns the number of times a Connection has been closed by the reapIdleConnections() method due to being checked out for longer than the checkoutSeconds interval.
getNumRequests()
  Returns the number of times a Connection has been checked out from the pool
getNumWaits()
  Returns the number of times a thread has had to block on wait() as a result of all PooledConnections being in use.
reapIdleConnections()
  Check all connections to make sure they haven't: 1) gone idle for too long
  2) been checked out by a thread for too long (cursor leak)
removeAllConnections()
  Removes all connections from the pool and calls close() on them.
returnConnection(PooledConnection)
setTracing(boolean)
  Turns tracing on or off.
size()
  Returns the current number of Connections in the pool.

##

ConnectionPool

     public ConnectionPool(String alias,
                           String url,
                           String username,
                           String password,
                           int maxConn,
                           int timeoutSeconds,
                           int checkoutSeconds)

  Creates a Connection pool with no maxCheckout parameter.

  Parameters:
    alias - Name of the pool
    url - JDBC URL to connect to
    username - JDBC username to connect as
    password - username's password in the database
    maxConn - Maximum number of connections to open; When this limit is reached, threads requesting a connection are queued until a connection becomes available
    timeoutSeconds - Maximum number of seconds a Connection can go unused before it is closed
    checkoutSeconds - Maximum number of seconds a Thread can checkout a Connection before it is closed and returned to the pool. This is a protection against the Thread dying and leaving the Connection checked out indefinately

ConnectionPool

     public ConnectionPool(String alias,
                           String url,
                           String username,
                           String password,
                           int maxConn,
                           int timeoutSeconds,
                           int checkoutSeconds,
                           int maxCheckout)

  Creates a Connection pool

  Parameters:
    alias - Name of the pool
    url - JDBC URL to connect to
    username - JDBC username to connect as
    password - username's password in the database
    maxConn - Maximum number of connections to open; When this limit is reached, threads requesting a connection are queued until a connection becomes available
    timeoutSeconds - Maximum number of seconds a Connection can go unused before it is closed
    checkoutSeconds - Maximum number of seconds a Thread can checkout a Connection before it is closed and returned to the pool. This is a protection against the Thread dying and leaving the Connection checked out indefinately
    maxCheckout - If this is greater than 0, the number of times a Connection may be checked out before it is closed. Used as a safeguard against cursor leak, which occurs if you don't call ResultSet.close() and Statement.close()

##

setTracing

     public void setTracing(boolean on)

  Turns tracing on or off. If turned on, verbose messages about the pool will be printed to STDERR

getAlias

     public String getAlias()

  Returns the alias for this pool. This name is defined by the user in the constructor

getNumRequests

     public int getNumRequests()

  Returns the number of times a Connection has been checked out from the pool

getNumWaits

     public int getNumWaits()

  Returns the number of times a thread has had to block on wait() as a result of all PooledConnections being in use. Useful diagnostic tool to see if your pool needs more nodes (which could require a database license upgrade if you're running Oracle for instance)

getNumCheckoutTimeouts

     public int getNumCheckoutTimeouts()

  Returns the number of times a Connection has been closed by the reapIdleConnections() method due to being checked out for longer than the checkoutSeconds interval.

  If this is greater than 0 it means that you either have queries that take longer to execute than the checkoutSeconds interval allows, or it means that you are forgetting to call conn.close() somewhere in your application. Both conditions are undesirable, but they have different solutions. In the latter case either tune your query to execute more quickly, or increase the checkoutSeconds parameter to the pool. In the former case you simply need to find the code that calls DriverManager.getConnection() but not conn.close()

getMaxConn

     public int getMaxConn()

  Returns the maximum number of connections this pool can open

size

     public int size()

  Returns the current number of Connections in the pool.

reapIdleConnections

     public synchronized void reapIdleConnections()

  Check all connections to make sure they haven't: 1) gone idle for too long
  2) been checked out by a thread for too long (cursor leak)

removeAllConnections

     public synchronized void removeAllConnections()

  Removes all connections from the pool and calls close() on them. It squelches any SQLExceptions that might results from close(). That's probably not ideal.

getConnection

     public synchronized Connection getConnection() throws SQLException

  Returns a connection for the pool. There are three ways this can happen:
  1. If a connection in the pool is free, it is locked and returned immediately
  2. If no connections are free, but the pool is not full, a new Connection is opened and returned
  3. If no connections are free, and the pool is full, the thread calls wait() and blocks until a connection is returned

returnConnection

     public synchronized void returnConnection(PooledConnection conn)

    All Packages  Class Hierarchy  This Package  Previous  Next  Index