Class Pool
java.lang.Object
org.mariadb.jdbc.internal.util.pool.Pool
- All Implemented Interfaces:
AutoCloseable,PoolMBean
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ThreadPoolExecutorprivate final BlockingQueue<Runnable> private longprivate GlobalStateInfoprivate final LinkedBlockingDeque<MariaDbPooledConnection> private static final Loggerprivate intprivate final Optionsprivate final AtomicIntegerprivate static final intprivate static final intprivate final ScheduledThreadPoolExecutorprivate final AtomicIntegerprivate final Stringprivate final ScheduledFutureprivate longprivate final AtomicIntegerprivate final UrlParser -
Constructor Summary
ConstructorsConstructorDescriptionPool(UrlParser urlParser, int poolIndex, ScheduledThreadPoolExecutor poolExecutor) Create pool from configuration. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCreate new connection.private voidAdd new connection if needed.voidclose()Close pool and underlying connections.private voidcloseAll(ExecutorService connectionRemover, Collection<MariaDbPooledConnection> collection) private MariaDbPooledConnectioncreatePoolConnection(MariaDbConnection connection) booleanprivate StringgeneratePoolTag(int poolIndex) longRetrieve new connection.getConnection(String username, String password) Get new connection from pool if user and password correspond to pool.longprivate MariaDbPooledConnectionprivate MariaDbPooledConnectiongetIdleConnection(long timeout, TimeUnit timeUnit) Get an existing idle connection in pool.longlonginthashCode()private voidinitializePoolGlobalState(MariaDbConnection connection) private voidprivate voidRemoving idle connection.voidJMX method to remove state (will be reinitialized on next connection creation).private voidprivate voidFor testing purpose only.private void
-
Field Details
-
logger
-
POOL_STATE_OK
private static final int POOL_STATE_OK- See Also:
-
POOL_STATE_CLOSING
private static final int POOL_STATE_CLOSING- See Also:
-
poolState
-
urlParser
-
options
-
pendingRequestNumber
-
totalConnection
-
idleConnections
-
connectionAppender
-
connectionAppenderQueue
-
poolTag
-
poolExecutor
-
scheduledFuture
-
globalInfo
-
maxIdleTime
private int maxIdleTime -
timeToConnectNanos
private long timeToConnectNanos -
connectionTime
private long connectionTime
-
-
Constructor Details
-
Pool
Create pool from configuration.- Parameters:
urlParser- configuration parserpoolIndex- pool index to permit distinction of thread namepoolExecutor- pools common executor
-
-
Method Details
-
addConnectionRequest
private void addConnectionRequest()Add new connection if needed. Only one thread create new connection, so new connection request will wait to newly created connection or for a released connection. -
removeIdleTimeoutConnection
private void removeIdleTimeoutConnection()Removing idle connection. Close them and recreate connection to reach minimal number of connection. -
addConnection
Create new connection.- Throws:
SQLException- if connection creation failed
-
getIdleConnection
- Throws:
InterruptedException
-
getIdleConnection
private MariaDbPooledConnection getIdleConnection(long timeout, TimeUnit timeUnit) throws InterruptedException Get an existing idle connection in pool.- Returns:
- an IDLE connection.
- Throws:
InterruptedException
-
silentCloseConnection
-
silentAbortConnection
-
createPoolConnection
-
getConnection
Retrieve new connection. If possible return idle connection, if not, stack connection query, ask for a connection creation, and loop until a connection become idle / a new connection is created.- Returns:
- a connection object
- Throws:
SQLException- if no connection is created when reaching timeout (connectTimeout option)
-
getConnection
Get new connection from pool if user and password correspond to pool. If username and password are different from pool, will return a dedicated connection.- Parameters:
username- usernamepassword- password- Returns:
- connection
- Throws:
SQLException- if any error occur during connection
-
generatePoolTag
-
getUrlParser
-
close
Close pool and underlying connections.- Specified by:
closein interfaceAutoCloseable- Throws:
InterruptedException- if interrupted
-
closeAll
private void closeAll(ExecutorService connectionRemover, Collection<MariaDbPooledConnection> collection) -
initializePoolGlobalState
- Throws:
SQLException
-
getPoolTag
-
equals
-
hashCode
public int hashCode() -
getGlobalInfo
-
getActiveConnections
public long getActiveConnections()- Specified by:
getActiveConnectionsin interfacePoolMBean
-
getTotalConnections
public long getTotalConnections()- Specified by:
getTotalConnectionsin interfacePoolMBean
-
getIdleConnections
public long getIdleConnections()- Specified by:
getIdleConnectionsin interfacePoolMBean
-
getConnectionRequests
public long getConnectionRequests()- Specified by:
getConnectionRequestsin interfacePoolMBean
-
registerJmx
- Throws:
Exception
-
unRegisterJmx
- Throws:
Exception
-
testGetConnectionIdleThreadIds
For testing purpose only.- Returns:
- current thread id's
-
resetStaticGlobal
public void resetStaticGlobal()JMX method to remove state (will be reinitialized on next connection creation).- Specified by:
resetStaticGlobalin interfacePoolMBean
-