Package org.mariadb.jdbc.pool
Class Pool
java.lang.Object
org.mariadb.jdbc.pool.Pool
- All Implemented Interfaces:
AutoCloseable
,PoolMBean
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Configuration
private final ThreadPoolExecutor
private final BlockingQueue<Runnable>
private final LinkedBlockingDeque<InternalPoolConnection>
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
-
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<InternalPoolConnection> collection) private String
generatePoolTag
(int poolIndex) long
getConf()
long
private InternalPoolConnection
getIdleConnection
(long timeout, TimeUnit timeUnit) Get an existing idle connection in pool.long
Retrieve new connection.getPoolConnection
(String username, String password) Get new connection from pool if user and password correspond to pool.long
private 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
-
-
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 InternalPoolConnection 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 InternalPoolConnection 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
Close pool and underlying connections.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
closeAll
-
getPoolTag
-
getActiveConnections
public long getActiveConnections()- Specified by:
getActiveConnections
in interfacePoolMBean
-
getTotalConnections
public long getTotalConnections()- Specified by:
getTotalConnections
in interfacePoolMBean
-
getIdleConnections
public long getIdleConnections()- Specified by:
getIdleConnections
in interfacePoolMBean
-
getConnectionRequests
public long getConnectionRequests()- Specified by:
getConnectionRequests
in interfacePoolMBean
-
registerJmx
- Throws:
Exception
-
unRegisterJmx
- Throws:
Exception
-
testGetConnectionIdleThreadIds
For testing purpose only.- Returns:
- current thread id's
-