com.ibm.as400.access
Class ConnectionPool

java.lang.Object
  extended by com.ibm.as400.access.ConnectionPool
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AS400ConnectionPool, AS400JDBCConnectionPool

public abstract class ConnectionPool
extends Object
implements Serializable

Represents a pool of connections to the system.

ConnectionPool objects generate the following events:

See Also:
Serialized Form

Constructor Summary
Constructor and Description
ConnectionPool()
           
 
Method Summary
Modifier and Type Method and Description
 void addConnectionPoolListener(ConnectionPoolListener listener)
          Adds a ConnectionPoolListener.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener.
abstract  void close()
          Closes the connection pool.
protected  void finalize()
          Closes the connection pool if not explicitly closed by the caller.
 long getCleanupInterval()
          Returns the time interval for how often the maintenance daemon is run.
 int getMaxConnections()
          Returns the maximum number of connections.
 long getMaxInactivity()
          Returns the maximum amount of inactive time before an available connection is closed.
 long getMaxLifetime()
          Returns the maximum life for an available connection.
 int getMaxUseCount()
          Returns the maximum number of times a connection can be used before it is replaced in the pool.
 long getMaxUseTime()
          Returns the maximum amount of time a connection can be in use before it is closed and returned to the pool.
 boolean isRunMaintenance()
          Indicates whether the maintenance thread is used to cleanup expired connections.
 boolean isThreadUsed()
          Indicates whether threads are used in communication with the host servers and for running maintenance.
 void removeConnectionPoolListener(ConnectionPoolListener listener)
          Removes a ConnectionPoolListener.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener.
 void setCleanupInterval(long cleanupInterval)
          Sets the time interval for how often the maintenance daemon is run.
 void setMaxConnections(int maxConnections)
          Sets the maximum number of connections.
 void setMaxInactivity(long maxInactivity)
          Sets the maximum amount of inactive time before an available connection is closed.
 void setMaxLifetime(long maxLifetime)
          Sets the maximum life for an available connection.
 void setMaxUseCount(int maxUseCount)
          Sets the maximum number of times a connection can be used before it is replaced in the pool.
 void setMaxUseTime(long maxUseTime)
          Sets the maximum amount of time a connection can be in use before it is closed and returned to the pool.
 void setRunMaintenance(boolean cleanup)
          Sets whether the Toolbox does periodic maintenance on the connection pool to clean up expired connections.
 void setThreadUsed(boolean useThreads)
          Sets whether the IBM Toolbox for Java uses additional threads.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool()
Method Detail

addConnectionPoolListener

public void addConnectionPoolListener(ConnectionPoolListener listener)
Adds a ConnectionPoolListener.

Parameters:
listener - The ConnectionPoolListener.
See Also:
removeConnectionPoolListener(com.ibm.as400.access.ConnectionPoolListener)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener.

Parameters:
listener - The PropertyChangeListener.
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

close

public abstract void close()
                    throws ConnectionPoolException
Closes the connection pool.

Throws:
ConnectionPoolException - If a pool error occurs.

finalize

protected void finalize()
                 throws Throwable
Closes the connection pool if not explicitly closed by the caller.

Overrides:
finalize in class Object
Throws:
Throwable - If an error occurs.

getCleanupInterval

public long getCleanupInterval()
Returns the time interval for how often the maintenance daemon is run. The default value is 300000 milliseconds (5 minutes).

Returns:
Number of milliseconds.

getMaxConnections

public int getMaxConnections()
Returns the maximum number of connections. The default value is -1 indicating no limit to the number of connections.

Returns:
Maximum number of connections.

getMaxInactivity

public long getMaxInactivity()
Returns the maximum amount of inactive time before an available connection is closed. The maintenance daemon closes the connection if the threshold is reached. The default value is 60 minutes. A value of -1 indicates that there is no limit.

Returns:
Number of milliseconds.

getMaxLifetime

public long getMaxLifetime()
Returns the maximum life for an available connection. The maintenance daemon closes the available connection if the threshold is reached. The default value is a 24 hour limit. A value of -1 indicates that there is no limit.

Returns:
Number of milliseconds.

getMaxUseCount

public int getMaxUseCount()
Returns the maximum number of times a connection can be used before it is replaced in the pool. The default value is -1. A value of -1 indicates that there is no limit.

Returns:
Maximum usage count.

getMaxUseTime

public long getMaxUseTime()
Returns the maximum amount of time a connection can be in use before it is closed and returned to the pool. The default value is -1 indicating that there is no limit.

Returns:
Number of milliseconds.

isRunMaintenance

public boolean isRunMaintenance()
Indicates whether the maintenance thread is used to cleanup expired connections. The default is true.

Returns:
true if expired connection are cleaned up by the maintenance thread; false otherwise.

isThreadUsed

public boolean isThreadUsed()
Indicates whether threads are used in communication with the host servers and for running maintenance. This property affects AS400ConnectionPool and not AS400JDBCConnectionPool which is written to the JDBC specification. The default value is true.

Returns:
true if threads are used; false otherwise.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener.

Parameters:
listener - The PropertyChangeListener.
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

removeConnectionPoolListener

public void removeConnectionPoolListener(ConnectionPoolListener listener)
Removes a ConnectionPoolListener.

Parameters:
listener - The ConnectionPoolListener.
See Also:
addConnectionPoolListener(com.ibm.as400.access.ConnectionPoolListener)

setCleanupInterval

public void setCleanupInterval(long cleanupInterval)
Sets the time interval for how often the maintenance daemon is run. The default value is 300000 milliseconds or 5 minutes.

Parameters:
cleanupInterval - The number of milliseconds.

setMaxConnections

public void setMaxConnections(int maxConnections)
Sets the maximum number of connections. The default value is -1 indicating no limit to the number of connections.

Parameters:
maxConnections - Maximum number of connections.

setMaxInactivity

public void setMaxInactivity(long maxInactivity)
Sets the maximum amount of inactive time before an available connection is closed. The maintenance daemon closes the connection if the threshold is reached. The default value is 60 minutes. A value of -1 indicates that there is no limit.

Parameters:
maxInactivity - Number of milliseconds.

setMaxLifetime

public void setMaxLifetime(long maxLifetime)
Sets the maximum life for an available connection. The maintenance daemon closes the available connection if the threshold is reached. The default value is a 24 hour limit. A value of -1 indicates that there is no limit.

Parameters:
maxLifetime - Number of milliseconds.

setMaxUseCount

public void setMaxUseCount(int maxUseCount)
Sets the maximum number of times a connection can be used before it is replaced in the pool. The default value is -1. A value of -1 indicates that there is no limit.

Parameters:
maxUseCount - Maximum usage count.

setMaxUseTime

public void setMaxUseTime(long maxUseTime)
Sets the maximum amount of time a connection can be in use before it is closed and returned to the pool. The default value is -1 indicating that there is no limit.

Parameters:
maxUseTime - Number of milliseconds.

setRunMaintenance

public void setRunMaintenance(boolean cleanup)
Sets whether the Toolbox does periodic maintenance on the connection pool to clean up expired connections. If setThreadUsed is true, the Toolbox starts an extra thread to perform maintenance. If setThreadUsed is false, the Toolbox will perform maintenance on the user's thread when it uses the connection pool. This method and setThreadUsed can be set in interchangeable order. The default value is true.

Parameters:
cleanup - If expired connections are cleaned up by the maintenance daemon.

setThreadUsed

public void setThreadUsed(boolean useThreads)
Sets whether the IBM Toolbox for Java uses additional threads. The Toolbox creates additional threads for various purposes, including: Letting the IBM Toolbox for Java use additional threads will be beneficial to performance, but turning threads off may be necessary if your application needs to be compliant with the Enterprise Java Beans specification. The threadUsed property cannot be changed once the pool is in use. This property affects AS400ConnectionPool and not AS400JDBCConnectionPool, which is written to the JDBC specification. This method and setRunMaintenance can be called in interchangeable order. The default value is true.

Parameters:
useThreads - true to use additional threads; false otherwise.