Class Pool
java.lang.Object
org.mariadb.jdbc.pool.Pool
- All Implemented Interfaces:
AutoCloseable, PoolMBean
MariaDB Pool
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Configurationprivate final ThreadPoolExecutorprivate final BlockingQueue<Runnable> private final LinkedBlockingDeque<MariaDbInnerPoolConnection> private static final Loggerprivate final AtomicIntegerprivate static final intprivate static final intprivate final ScheduledThreadPoolExecutorprivate final AtomicIntegerprivate final Stringprivate final ScheduledFuture<?> private final AtomicIntegerprivate int -
Constructor Summary
ConstructorsConstructorDescriptionPool(Configuration conf, 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(Collection<MariaDbInnerPoolConnection> collection) private StringgeneratePoolTag(int poolIndex) longget pool active connection numbergetConf()Get current configurationlongget connection waiting request numberprivate MariaDbInnerPoolConnectiongetIdleConnection(long timeout, TimeUnit timeUnit) Get an existing idle connection in pool.longget idle connection numberRetrieve new connection.getPoolConnection(String username, String password) Get new connection from pool if user and password correspond to pool.return pool taglongget pool total connectionprivate voidprivate voidRemoving idle connection.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
-
conf
-
pendingRequestNumber
-
totalConnection
-
idleConnections
-
connectionAppender
-
connectionAppenderQueue
-
poolTag
-
poolExecutor
-
scheduledFuture
-
waitTimeout
private int waitTimeout
-
-
Constructor Details
-
Pool
Create pool from configuration.- Parameters:
conf- 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
private MariaDbInnerPoolConnection getIdleConnection(long timeout, TimeUnit timeUnit) throws InterruptedException Get an existing idle connection in pool.- Returns:
- an IDLE connection.
- Throws:
InterruptedException
-
silentCloseConnection
-
silentAbortConnection
-
getPoolConnection
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)
-
getPoolConnection
public MariaDbInnerPoolConnection getPoolConnection(String username, String password) throws SQLException 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
-
getConf
-
close
public void close()Close pool and underlying connections.- Specified by:
closein interfaceAutoCloseable
-
closeAll
-
getPoolTag
-
getActiveConnections
public long getActiveConnections()Description copied from interface:PoolMBeanget pool active connection number- Specified by:
getActiveConnectionsin interfacePoolMBean- Returns:
- pool active connection number
-
getTotalConnections
public long getTotalConnections()Description copied from interface:PoolMBeanget pool total connection- Specified by:
getTotalConnectionsin interfacePoolMBean- Returns:
- pool total connection number
-
getIdleConnections
public long getIdleConnections()Description copied from interface:PoolMBeanget idle connection number- Specified by:
getIdleConnectionsin interfacePoolMBean- Returns:
- idle connection number
-
getConnectionRequests
public long getConnectionRequests()Description copied from interface:PoolMBeanget connection waiting request number- Specified by:
getConnectionRequestsin interfacePoolMBean- Returns:
- request number
-
registerJmx
-
unRegisterJmx
-
testGetConnectionIdleThreadIds
-