Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public abstract class AOPool<C,E extends Exception,I extends Exception> extends Thread
ThreadLocal list of connections
checked-out by the current thread is maintained. When getting a new connection,
this is used to check again maxConnections instead of checking
the global lists.
Idea: Add some sort of thread-connection affinity, where the same connection
slot will be used by the same thread when it is available. This should
help cache locality.
Idea: When connections are closed due to maxConnectionAge, automatically reconnect
in the background. This would avoid the latency of the reconnect for the
connection-using thread.Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CONNECT_TIMEOUT |
static int |
DEFAULT_DELAY_TIME |
static long |
DEFAULT_MAX_CONNECTION_AGE |
static int |
DEFAULT_MAX_IDLE_TIME |
static int |
DEFAULT_SOCKET_SO_LINGER |
protected Logger |
logger
All warnings are sent here if available, otherwise will be written to
System.err. |
static long |
UNLIMITED_MAX_CONNECTION_AGE |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Modifier | Constructor and Description |
|---|---|
protected |
AOPool(int delayTime,
int maxIdleTime,
String name,
int poolSize,
long maxConnectionAge,
Logger logger) |
protected |
AOPool(String name,
int poolSize,
long maxConnectionAge,
Logger logger) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Shuts down the pool, exceptions during close will be logged as a warning and not thrown.
|
protected abstract void |
close(C conn) |
int |
getConcurrency()
Gets the number of connections that are currently busy.
|
C |
getConnection()
Gets a connection, warning of a connection is already used by this thread.
|
C |
getConnection(int maxConnections)
Gets either an available connection or creates a new connection.
|
int |
getConnectionCount()
Gets the number of connections currently connected.
|
protected abstract C |
getConnectionObject()
Creates a new connection.
|
long |
getConnects()
Gets the total number of connects for the entire pool.
|
Logger |
getLogger() |
int |
getMaxConcurrency() |
long |
getMaxConnectionAge()
Gets the maximum age for connections.
|
int |
getPoolSize() |
long |
getTotalTime() |
long |
getTransactionCount() |
protected abstract boolean |
isClosed(C conn) |
protected abstract E |
newException(String message,
Throwable cause) |
protected abstract I |
newInterruptedException(String message,
Throwable cause) |
protected abstract void |
printConnectionStats(Appendable out)
Prints additional connection pool details.
|
void |
printStatisticsHTML(Appendable out)
Prints complete statistics about connection pool use.
|
void |
releaseConnection(C connection)
Releases the database
Connection to the Connection pool. |
protected abstract void |
resetConnection(C conn) |
void |
run()
The RefreshConnection thread polls every connection in the connection pool.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldpublic static final int DEFAULT_DELAY_TIME
public static final int DEFAULT_MAX_IDLE_TIME
public static final long UNLIMITED_MAX_CONNECTION_AGE
public static final long DEFAULT_MAX_CONNECTION_AGE
public static final int DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_SOCKET_SO_LINGER
protected final Logger logger
System.err.public final void close()
public final int getConcurrency()
public final int getConnectionCount()
public C getConnection() throws I extends Exception, E extends Exception
I - when interruptedE - when errorI extends ExceptiongetConnection(int)public C getConnection(int maxConnections) throws I extends Exception, E extends Exception
ThreadLocal
optimizations, the connection returned must be released by the current thread,
it should not be passed off to another thread before release.protected abstract C getConnectionObject() throws I extends Exception, E extends Exception
public final long getConnects()
public final long getMaxConnectionAge()
public final int getMaxConcurrency()
public final int getPoolSize()
public final long getTotalTime()
public final long getTransactionCount()
protected abstract void printConnectionStats(Appendable out) throws IOException
IOExceptionpublic final void printStatisticsHTML(Appendable out) throws IOException, E extends Exception
IOExceptionE extends Exceptionpublic final void releaseConnection(C connection) throws E extends Exception
Connection to the Connection pool.
It is safe to call this method more than once, but only the first call will
have any affect and the second release will log a warning.protected abstract void resetConnection(C conn) throws I extends Exception, E extends Exception
public final void run()
protected abstract I newInterruptedException(String message, Throwable cause)
public final Logger getLogger()
Copyright © 2000–2016 AO Industries, Inc.. All rights reserved.