public class ConnectionPool extends Object implements org.avaje.datasource.DataSourcePool
| Modifier and Type | Class and Description |
|---|---|
static class |
ConnectionPool.Status |
| Constructor and Description |
|---|
ConnectionPool(String name,
org.avaje.datasource.DataSourceConfig params) |
| Modifier and Type | Method and Description |
|---|---|
void |
closeBusyConnections(long leakTimeMinutes)
Close any busy connections that have not been used for some time.
|
Connection |
createUnpooledConnection()
Create a Connection that will not be part of the connection pool.
|
void |
dumpBusyConnectionInformation()
Dumps the busy connection information to the logs.
|
String |
getBusyConnectionInformation()
Returns information describing connections that are currently being used.
|
Connection |
getConnection()
Return a pooled connection.
|
Connection |
getConnection(String username,
String password)
Create an un-pooled connection with the given username and password.
|
long |
getLeakTimeMinutes()
Return the number of minutes after which a busy connection could be
considered leaked from the connection pool.
|
int |
getLoginTimeout()
Not implemented and shouldn't be used.
|
PrintWriter |
getLogWriter()
Returns null.
|
long |
getMaxAgeMillis()
Return the maximum age a connection is allowed to be before it is trimmed
out of the pool.
|
int |
getMaxInactiveMillis()
Return the time after which inactive connections are trimmed.
|
int |
getMaxSize()
Return the max size this pool can grow to.
|
int |
getMinSize()
Return the min size this pool should maintain.
|
String |
getName()
Return the dataSource name.
|
Logger |
getParentLogger() |
int |
getPstmtCacheSize()
Return the preparedStatement cache size.
|
org.avaje.datasource.PoolStatistics |
getStatistics(boolean reset)
Return the aggregated load statistics collected on all the connections in the pool.
|
org.avaje.datasource.PoolStatus |
getStatus(boolean reset)
Return the current status of the connection pool.
|
int |
getWaitTimeoutMillis()
Return the time in millis that threads will wait when the pool has hit
the max size.
|
int |
getWarningSize()
Return the warning size.
|
boolean |
isAutoCommit()
Return the default autoCommit setting Connections in this pool will use.
|
boolean |
isCaptureStackTrace()
Return true if the connection pool is currently capturing the StackTrace
when connections are 'got' from the pool.
|
boolean |
isDataSourceUp()
Returns false when the dataSource is down.
|
boolean |
isWrapperFor(Class<?> arg0)
Returns false.
|
void |
reset()
Close all the connections in the pool.
|
void |
setCaptureStackTrace(boolean captureStackTrace)
Set this to true means that the StackElements are captured every time a
connection is retrieved from the pool.
|
void |
setLeakTimeMinutes(long leakTimeMinutes)
For detecting and closing leaked connections.
|
void |
setLoginTimeout(int seconds)
Not implemented and shouldn't be used.
|
void |
setLogWriter(PrintWriter writer)
Not implemented.
|
void |
setMaxSize(int max)
Set a new maximum size.
|
void |
setMinSize(int min)
Set the min size this pool should maintain.
|
void |
setPstmtCacheSize(int pstmtCacheSize)
Set the preparedStatement cache size.
|
void |
setWarningSize(int warningSize)
Set a new maximum size.
|
void |
shutdown(boolean deregisterDriver)
This will close all the free connections, and then go into a wait loop,
waiting for the busy connections to be freed.
|
void |
testAlert()
Send a message to the DataSourceAlertListener to test it.
|
<T> T |
unwrap(Class<T> arg0)
Not Implemented.
|
public ConnectionPool(String name, org.avaje.datasource.DataSourceConfig params)
public Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface CommonDataSourceSQLFeatureNotSupportedExceptionpublic boolean isWrapperFor(Class<?> arg0) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic <T> T unwrap(Class<T> arg0) throws SQLException
unwrap in interface WrapperSQLExceptionpublic String getName()
getName in interface org.avaje.datasource.DataSourcePoolpublic boolean isDataSourceUp()
public Connection createUnpooledConnection() throws SQLException
When this connection is closed it will not go back into the pool.
If withDefaults is true then the Connection will have the autoCommit and transaction isolation set to the defaults for the pool.
SQLExceptionpublic void setMaxSize(int max)
public int getMaxSize()
public void setMinSize(int min)
public int getMinSize()
public void setWarningSize(int warningSize)
public int getWarningSize()
public int getWaitTimeoutMillis()
public int getMaxInactiveMillis()
public long getMaxAgeMillis()
public String getBusyConnectionInformation()
public void dumpBusyConnectionInformation()
This includes the stackTrace elements if they are being captured. This is useful when needing to look a potential connection pool leaks.
public void closeBusyConnections(long leakTimeMinutes)
These connections are considered to have leaked from the connection pool.
Connection leaks occur when code doesn't ensure that connections are closed() after they have been finished with. There should be an appropriate try catch finally block to ensure connections are always closed and put back into the pool.
public void reset()
public Connection getConnection() throws SQLException
getConnection in interface DataSourceSQLExceptionpublic void testAlert()
public void shutdown(boolean deregisterDriver)
The DataSources's should be shutdown AFTER thread pools. Leaked Connections are not waited on, as that would hang the server.
shutdown in interface org.avaje.datasource.DataSourcePoolpublic boolean isAutoCommit()
isAutoCommit in interface org.avaje.datasource.DataSourcePoolpublic boolean isCaptureStackTrace()
This is set to true to help diagnose connection pool leaks.
public void setCaptureStackTrace(boolean captureStackTrace)
public Connection getConnection(String username, String password) throws SQLException
getConnection in interface DataSourceSQLExceptionpublic int getLoginTimeout() throws SQLException
getLoginTimeout in interface CommonDataSourceSQLExceptionpublic void setLoginTimeout(int seconds) throws SQLException
setLoginTimeout in interface CommonDataSourceSQLExceptionpublic PrintWriter getLogWriter()
getLogWriter in interface CommonDataSourcepublic void setLogWriter(PrintWriter writer) throws SQLException
setLogWriter in interface CommonDataSourceSQLExceptionpublic void setLeakTimeMinutes(long leakTimeMinutes)
If you want to use a connection for that longer then you should consider creating an unpooled connection or setting longRunning to true on that connection.
public long getLeakTimeMinutes()
public int getPstmtCacheSize()
public void setPstmtCacheSize(int pstmtCacheSize)
public org.avaje.datasource.PoolStatus getStatus(boolean reset)
If you pass reset = true then the counters such as hitCount, waitCount and highWaterMark are reset.
getStatus in interface org.avaje.datasource.DataSourcePoolpublic org.avaje.datasource.PoolStatistics getStatistics(boolean reset)
getStatistics in interface org.avaje.datasource.DataSourcePoolCopyright © 2016. All rights reserved.