Class Pool
java.lang.Object
org.mariadb.jdbc.internal.util.pool.Pool
- All Implemented Interfaces:
AutoCloseable
,PoolMBean
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ThreadPoolExecutor
private final BlockingQueue<Runnable>
private long
private GlobalStateInfo
private final LinkedBlockingDeque<MariaDbPooledConnection>
private static final Logger
private int
private final Options
private final AtomicInteger
private static final int
private static final int
private final ScheduledThreadPoolExecutor
private final AtomicInteger
private final String
private final ScheduledFuture
private long
private final AtomicInteger
private final UrlParser
-
Constructor Summary
ConstructorsConstructorDescriptionPool
(UrlParser urlParser, 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
(ExecutorService connectionRemover, Collection<MariaDbPooledConnection> collection) private MariaDbPooledConnection
createPoolConnection
(MariaDbConnection connection) boolean
private String
generatePoolTag
(int poolIndex) long
Retrieve new connection.getConnection
(String username, String password) Get new connection from pool if user and password correspond to pool.long
private MariaDbPooledConnection
private MariaDbPooledConnection
getIdleConnection
(long timeout, TimeUnit timeUnit) Get an existing idle connection in pool.long
long
int
hashCode()
private void
initializePoolGlobalState
(MariaDbConnection connection) private void
private void
Removing idle connection.void
JMX method to remove state (will be reinitialized on next connection creation).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
-
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:
close
in 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:
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
-
resetStaticGlobal
public void resetStaticGlobal()JMX method to remove state (will be reinitialized on next connection creation).- Specified by:
resetStaticGlobal
in interfacePoolMBean
-