|
: Class ConnectionPool
com.bitmechanic.sql
|
Constructor Summary | |
ConnectionPool(java.lang.String alias,
java.lang.String url,
java.lang.String username,
java.lang.String password,
int maxConn,
int timeoutSeconds,
int checkoutSeconds)
Creates a Connection pool with no maxCheckout parameter. |
|
ConnectionPool(java.lang.String alias,
java.lang.String url,
java.lang.String username,
java.lang.String password,
int maxConn,
int timeoutSeconds,
int checkoutSeconds,
int maxCheckout)
Creates a Connection pool |
Method Summary | |
java.lang.String |
dumpInfo()
Dump some information about all connections |
java.lang.String |
getAlias()
Returns the alias for this pool. |
boolean |
getCacheStatements()
Returns whether connections in this pool will cache Statement and PreparedStatement objects. |
java.sql.Connection |
getConnection()
Returns a connection for the pool. |
int |
getMaxConn()
Returns the maximum number of connections this pool can open |
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. |
int |
getNumRequests()
Returns the number of times a Connection has been checked out from the pool |
int |
getNumWaits()
Returns the number of times a thread has had to block on wait() as a result of all PooledConnections being in use. |
int |
getPrefetchSize()
Get the current prefetch size |
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) |
void |
removeAllConnections()
Removes all connections from the pool and calls close() on them. |
void |
returnConnection(PooledConnection conn)
|
void |
setCacheStatements(boolean cacheStmts)
If set to true, connections in the pool will reuse Statements and PreparedStatements. |
void |
setPrefetchSize(int newPrefetchSize)
Change the number of rows prefetched for a result set, for those drivers that support it. |
void |
setTracing(boolean on)
Turns tracing on or off. |
int |
size()
Returns the current number of Connections in the pool. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public ConnectionPool(java.lang.String alias, java.lang.String url, java.lang.String username, java.lang.String password, int maxConn, int timeoutSeconds, int checkoutSeconds)
alias
- Name of the poolurl
- JDBC URL to connect tousername
- JDBC username to connect aspassword
- username's password in the databasemaxConn
- Maximum number of connections to open; When this limit
is reached, threads requesting a connection are queued
until a connection becomes availabletimeoutSeconds
- Maximum number of seconds a Connection can go
unused before it is closedcheckoutSeconds
- 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
indefinatelypublic ConnectionPool(java.lang.String alias, java.lang.String url, java.lang.String username, java.lang.String password, int maxConn, int timeoutSeconds, int checkoutSeconds, int maxCheckout)
alias
- Name of the poolurl
- JDBC URL to connect tousername
- JDBC username to connect aspassword
- username's password in the databasemaxConn
- Maximum number of connections to open; When this limit
is reached, threads requesting a connection are queued
until a connection becomes availabletimeoutSeconds
- Maximum number of seconds a Connection can go
unused before it is closedcheckoutSeconds
- 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
indefinatelymaxCheckout
- 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()Method Detail |
public void setCacheStatements(boolean cacheStmts)
Set this to false if you want to run multiple Statements over the same Connection.
This is set to 'true' by default.
public boolean getCacheStatements()
public void setTracing(boolean on)
public java.lang.String getAlias()
public int getNumRequests()
public int getNumWaits()
public int getNumCheckoutTimeouts()
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()
public int getMaxConn()
public int size()
public void reapIdleConnections()
public void removeAllConnections()
public java.sql.Connection getConnection() throws java.sql.SQLException
public void returnConnection(PooledConnection conn)
public java.lang.String dumpInfo()
public void setPrefetchSize(int newPrefetchSize)
newPrefetchSize
- the new prefetch size to use, -1 for the defaultpublic int getPrefetchSize()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |