public class ConnectionPool extends ObjectPool<CacheConnection>
CacheConnection,
CachedCallableStatement,
CachedPreparedStatementObjectPool.Strategylog| Constructor and Description |
|---|
ConnectionPool(String name,
int minPool,
int maxPool,
int maxSize,
long idleTimeout,
String url,
Properties props)
Creates a new
ConnectionPool instance. |
ConnectionPool(String name,
int minPool,
int maxPool,
int maxSize,
long idleTimeout,
String url,
String username,
String password)
Creates a new
ConnectionPool instance. |
ConnectionPool(String name,
int maxPool,
int maxSize,
long idleTimeout,
String url,
Properties props)
Creates a new
ConnectionPool instance (with minPool=0). |
ConnectionPool(String name,
int maxPool,
int maxSize,
long idleTimeout,
String url,
String username,
String password)
Creates a new
ConnectionPool instance (with minPool=0). |
| Modifier and Type | Method and Description |
|---|---|
void |
addConnectionPoolListener(ConnectionPoolListener listener)
Adds a
ConnectionPoolListener to the event notification list. |
protected CacheConnection |
create()
Creates a new
Connection object. |
protected void |
destroy(CacheConnection cc)
Closes the specified
CacheConnection object. |
protected void |
freeConnection(Connection c)
Returns a
Connection to the pool (for internal use only). |
Connection |
getConnection()
Gets a
Connection from the pool. |
Connection |
getConnection(long timeout)
Gets a
Connection from the pool, waiting a maximum of
timeout milliseconds for one to become available,
returning null if not. |
protected float |
getIdleTimeoutMultiplier()
Returns the multiplier for adjusting the idle timeout unit.
|
protected long |
getMaximumCleaningInterval()
Specifies the maximum time interval between cleaning attempts of
the
Cleaner thread. |
protected long |
getMinimumCleaningInterval()
Specifies the minimum time interval between cleaning attempts of
the
Cleaner thread. |
PasswordDecoder |
getPasswordDecoder()
Returns the current
PasswordDecoder class. |
ConnectionValidator |
getValidator()
Returns the current
ConnectionValidator class. |
boolean |
isCachingCallableStatements()
Returns whether the pool caches
CallableStatement instances for each connection. |
boolean |
isCachingPreparedStatements()
Returns whether the pool caches
PreparedStatement instances for each connection. |
boolean |
isCachingStatements()
Returns whether the pool caches
Statement instances for each connection. |
boolean |
isRecycleAfterDelegateUse()
Returns whether connections may be recycled if the underlying
raw/delegate connection has been used.
|
protected boolean |
isValid(CacheConnection cc)
Validates a
CacheConnection object. |
protected void |
postRelease()
Method to give a sub-class the opportunity to cleanup resources after
the pool is officially released.
|
protected void |
preRelease()
Method to give a sub-class the opportunity to cleanup resources before
the pool is officially released.
|
void |
registerMBean()
Registers this pool with the platform MBean server.
|
void |
removeConnectionPoolListener(ConnectionPoolListener listener)
Removes a
ConnectionPoolListener from the event notification list. |
void |
setCaching(boolean b)
Determines whether to perform statement caching.
|
void |
setCaching(boolean ss,
boolean ps,
boolean cs)
Determines whether to perform statement caching.
|
void |
setPasswordDecoder(PasswordDecoder pd)
Sets the
PasswordDecoder class. |
void |
setRecycleAfterDelegateUse(boolean b)
Sets whether the connection may be recycled if the underlying
raw/delegate connection has been used (default: false).
|
void |
setValidator(ConnectionValidator cv)
Sets the validator class for
Connection instances. |
void |
unregisterMBean()
Removes this pool from the platform MBean server registration list.
|
addObjectPoolListener, checkIn, checkOut, checkOut, compareTo, equals, flush, getCheckedOut, getCustomLogger, getFreeCount, getIdleTimeout, getIdleTimeoutUnadjusted, getMaxPool, getMaxSize, getMinPool, getName, getParametersString, getPoolClass, getPoolHitRate, getPoolMissRate, getRequestCount, getSize, hashCode, init, init, isAsyncDestroy, isReleased, log_debug, log_debug, log_error, log_error, log_info, log_info, log_trace, log_trace, log_warn, log_warn, registerShutdownHook, release, releaseAsync, releaseForcibly, removeObjectPoolListener, removeShutdownHook, resetHitCounter, setAsyncDestroy, setLog, setParameters, setParameters, setSelectionStrategy, toStringpublic ConnectionPool(String name, int minPool, int maxPool, int maxSize, long idleTimeout, String url, String username, String password)
ConnectionPool instance.name - pool nameminPool - minimum number of pooled connections, or 0 for nonemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLusername - database usernamepassword - password for the database username suppliedpublic ConnectionPool(String name, int maxPool, int maxSize, long idleTimeout, String url, String username, String password)
ConnectionPool instance (with minPool=0).name - pool namemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLusername - database usernamepassword - password for the database username suppliedpublic ConnectionPool(String name, int minPool, int maxPool, int maxSize, long idleTimeout, String url, Properties props)
ConnectionPool instance.name - pool nameminPool - minimum number of pooled connections, or 0 for nonemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLprops - connection propertiespublic ConnectionPool(String name, int maxPool, int maxSize, long idleTimeout, String url, Properties props)
ConnectionPool instance (with minPool=0).name - pool namemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLprops - connection propertiespublic void registerMBean()
javax.management API.public void unregisterMBean()
javax.management API.protected CacheConnection create() throws SQLException
Connection object.create in class ObjectPool<CacheConnection>SQLExceptionprotected boolean isValid(CacheConnection cc)
CacheConnection object.isValid in class ObjectPool<CacheConnection>cc - connection to validatepublic void setValidator(ConnectionValidator cv)
Connection instances.cv - ConnectionValidator instance to use for this poolpublic ConnectionValidator getValidator()
ConnectionValidator class.ConnectionValidator classpublic void setPasswordDecoder(PasswordDecoder pd)
PasswordDecoder class.pd - PasswordDecoder instance to use for this poolpublic PasswordDecoder getPasswordDecoder()
PasswordDecoder class.PasswordDecoder classprotected void destroy(CacheConnection cc)
CacheConnection object.destroy in class ObjectPool<CacheConnection>cc - connection to destroypublic Connection getConnection() throws SQLException
Connection from the pool.null if nothing availableSQLException - if there is an error creating a new connectionpublic Connection getConnection(long timeout) throws SQLException
Connection from the pool, waiting a maximum of
timeout milliseconds for one to become available,
returning null if not.timeout - timeout value in millisecondsnull if nothing available within timeout periodSQLException - if there is an error getting a connectionprotected void freeConnection(Connection c) throws SQLException
Connection to the pool (for internal use only).
Connections obtained from the pool should be returned by calling
Connection.close().c - connection to free back to the poolSQLExceptionprotected void preRelease()
ObjectPoolObjectPool release implementation.preRelease in class ObjectPool<CacheConnection>protected void postRelease()
ObjectPoolObjectPool release implementation.
Be aware that the event-dispatch thread, cleaner thread, any init threads,
and the custom log have all been terminated before this method is called.postRelease in class ObjectPool<CacheConnection>protected float getIdleTimeoutMultiplier()
ObjectPoolgetIdleTimeoutMultiplier in class ObjectPool<CacheConnection>public final void setCaching(boolean b)
b - Whether to perform statement cachingpublic void setCaching(boolean ss,
boolean ps,
boolean cs)
ss - whether to cache Statement objectsps - whether to cache PreparedStatement objectscs - whether to cache CallableStatement objectspublic boolean isCachingStatements()
Statement instances for each connection.public boolean isCachingPreparedStatements()
PreparedStatement instances for each connection.public boolean isCachingCallableStatements()
CallableStatement instances for each connection.public final void setRecycleAfterDelegateUse(boolean b)
Each CacheConnection instance tracks whether a call to
CacheConnection.getDelegateConnection() has been made, and by default
prevents recycling of the connection if so, in order to help maintain
integrity of the pool. In certain circumstances it may be beneficial in
terms of performance to enable such recycling, provided the raw connections
are not compromised in any way, and the CacheConnection.close()
method is called on each CacheConnection instance and NOT the
raw connection.
b - whether connections are recycled after use of underlying delegate connectionpublic boolean isRecycleAfterDelegateUse()
protected long getMinimumCleaningInterval()
Cleaner thread.getMinimumCleaningInterval in class ObjectPool<CacheConnection>Cleaner threadprotected long getMaximumCleaningInterval()
Cleaner thread.getMaximumCleaningInterval in class ObjectPool<CacheConnection>Cleaner threadpublic final void addConnectionPoolListener(ConnectionPoolListener listener)
ConnectionPoolListener to the event notification list.listener - listener to addpublic final void removeConnectionPoolListener(ConnectionPoolListener listener)
ConnectionPoolListener from the event notification list.listener - listener to removeCopyright © 2014. All rights reserved.