Package org.mariadb.jdbc.pool
Class Pool
java.lang.Object
org.mariadb.jdbc.pool.Pool
- All Implemented Interfaces:
AutoCloseable
,PoolMBean
MariaDB Pool
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Configuration
private final ThreadPoolExecutor
private final BlockingQueue
<Runnable> private final LinkedBlockingDeque
<MariaDbInnerPoolConnection> private static final Logger
private final AtomicInteger
private static final int
private static final int
private final ScheduledThreadPoolExecutor
private final AtomicInteger
private final String
private final ScheduledFuture
<?> private final AtomicInteger
private int
-
Constructor Summary
ConstructorsConstructorDescriptionPool
(Configuration conf, int poolIndex, ScheduledThreadPoolExecutor poolExecutor) Create pool from configuration. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Create new connection.private void
Add new connection if needed.void
close()
Close pool and underlying connections.private void
closeAll
(Collection<MariaDbInnerPoolConnection> collection) private String
generatePoolTag
(int poolIndex) long
get pool active connection numbergetConf()
Get current configurationlong
get connection waiting request numberprivate MariaDbInnerPoolConnection
getIdleConnection
(long timeout, TimeUnit timeUnit) Get an existing idle connection in pool.long
get idle connection numberRetrieve new connection.getPoolConnection
(String username, String password) Get new connection from pool if user and password correspond to pool.return pool taglong
get pool total connectionprivate void
private void
Removing idle connection.private void
private void
For 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
Get current configuration- Returns:
- configuration
-
close
public void close()Close pool and underlying connections.- Specified by:
close
in interfaceAutoCloseable
-
closeAll
-
getPoolTag
return pool tag- Returns:
- pool tag
-
getActiveConnections
public long getActiveConnections()Description copied from interface:PoolMBean
get pool active connection number- Specified by:
getActiveConnections
in interfacePoolMBean
- Returns:
- pool active connection number
-
getTotalConnections
public long getTotalConnections()Description copied from interface:PoolMBean
get pool total connection- Specified by:
getTotalConnections
in interfacePoolMBean
- Returns:
- pool total connection number
-
getIdleConnections
public long getIdleConnections()Description copied from interface:PoolMBean
get idle connection number- Specified by:
getIdleConnections
in interfacePoolMBean
- Returns:
- idle connection number
-
getConnectionRequests
public long getConnectionRequests()Description copied from interface:PoolMBean
get connection waiting request number- Specified by:
getConnectionRequests
in interfacePoolMBean
- Returns:
- request number
-
registerJmx
- Throws:
Exception
-
unRegisterJmx
- Throws:
Exception
-
testGetConnectionIdleThreadIds
For testing purpose only.- Returns:
- current thread id's
-