Class ConnectionPool
- All Implemented Interfaces:
MBeanRegistration, NotificationBroadcaster, NotificationEmitter, ConnectionPoolMBean, PoolConfiguration
ConnectionPool. Provides management and monitoring
capabilities for connection pool statistics, operations, and configuration.
The ObjectName this MBean is registered under is fixed when the registration succeeds. A refused registration leaves
getObjectName() null until a later registration succeeds; getName() and getPoolName()
report the pool's live name and may differ from that registration name after a rename.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConcurrentLinkedQueue<NotificationListener> Listeners that are local and interested in our notifications, no need for JMXprotected ConnectionPoolThe pool this MBean wraps, assigned once by the constructor and never swapped: attribute reads consult the live configuration the pool shares with its DataSource, the operations run against this pool, and it is the pool the reported conditions describe.protected AtomicIntegersequence for JMX notificationsFields inherited from interface ConnectionPoolMBean
FAILED_QUERY_NOTIFICATION, NOTIFY_ABANDON, NOTIFY_CONNECT, NOTIFY_INIT, POOL_EMPTY, SLOW_QUERY_NOTIFICATION, SUSPECT_ABANDONED_NOTIFICATION, SUSPECT_RETURNED_NOTIFICATIONFields inherited from interface PoolConfiguration
PKG_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionConnectionPool(ConnectionPool pool) Creates a new JMX wrapper for the given connection pool. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a local notification listener that receives pool notifications without requiring JMX registration.voidLooks through the connections that are currently checked out for ones that have been held too long.voidRuns the idle-eviction pass over the connections that are currently idle.intConnections that have been abandoned (timed out) won't get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.intReturns the number of active (in-use) connections: the entries of the pool's busy set, which is what the pool counts as checked out rather than idle.longReturns the total number of connections borrowed since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.booleanReturns whether the pool commits any pending transaction when a connection is returned.Returns the connection properties with any credential they carry masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold.longReturns the total number of connections created since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.Returns a datasource, if one exists that is being used to create connections.Returns the JNDI string configured for data source usage.Returns a copy of the database properties with the credential entries removed, so the JMX surface does not expose the plaintext password whilegetPassword()is explicitly masked.The default auto-commit state of connections created by this pool.If non null, during connection creation the methodConnection.setCatalog(String)will be called with the set value.static MBeanNotificationInfo[]Returns the default notification info describing all notification types that this MBean can send.If non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value.intReturns the default transaction isolation level.The fully qualified Java class name of the JDBC driver to be used.intgetIdle()Returns the number of idle connections in the pool, meaning the entries that sit in the idle queue - among which there can be a wake-up placeholder with no session behind it.intReturns the number of connections that will be established when the connection pool is started.A custom query to be run when a connection is first created.Returns the interceptor configuration with any credential its definitions carry masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold - the parameter list of a definition reaches a third-party interceptor as configured, so it is one of the raw strings an operator may type a credential into.Returns the parsed interceptor configuration with any credential its definitions carry masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold - the pairs of a definition reach a third-party interceptor as configured, which is whygetJdbcInterceptors()masks them in the string this attribute is the parsed form of.booleanReturns true if errors that happen during validation will be loggedintThe maximum number of active connections that can be allocated from this pool at the same time.longTime in milliseconds to keep this connection before reconnecting.intThe maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()returns false.intThe maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()has been reached) for a connection to be returned before throwing an exception.intThe minimum amount of time an object must sit idle in the pool before it is eligible for eviction.intThe minimum number of established connections that should be kept in the pool at all times.getName()Returns the pool's current name, as theNameattribute.protected ObjectReturns the source the pool's notifications are sent with.intReturns the number of active (in-use) connections.intReturns the number of idle connections in the pool.intProperty not usedReturns the JMX ObjectName under which this MBean is registered.Returns the password used when establishing connections to the database.getPool()Returns the underlying connection pool instance.Returns the pool's current name, as thePoolNameattribute.Returns the pool configuration for the wrapped connection pool.booleanReturns true if the pool is configured to propagate interrupt state of a thread.longReturns the total number of reconnections since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.longReturns the total number of connections released since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.longReturns the total number of idle connections released since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.longReturns the total number of connections removed due to abandonment since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.intThe time in seconds before a connection can be considered abandoned.longReturns the total number of connections returned since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.booleanReturns whether the pool rolls back any pending transaction when a connection is returned.intgetSize()Returns the number of connection slots the pool holds right now - the idle ones and the checked out ones together.intReturns the time in seconds to pass before a connection is marked an abandoned suspect.intThe number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.getUrl()Returns the JDBC URL with any credential it carries masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold.booleanDeprecated.The disposable connection facade is always used, so this property no longer has any effect.booleanReturn true if a lock should be used when operations are performed on the connection object.Returns the username used to establish the connection withbooleanDeprecated.The statement facade is always used, so this property no longer has any effect.longavoid excess validation, only run validation at most at this frequency - time in milliseconds.The SQL query that will be used to validate connections from this pool before returning them to the caller or pool.intThe timeout in seconds before a connection validation queries fail.Returns the validator object used for connection validation.Return the name of the optional validator class - may be null.intReturns the number of threads waiting for a connection.booleanProperty not used.booleanReturns true if the callgetConnection(username,password)is allowed.The default auto-commit state of connections created by this pool.If non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value.booleanReturnstrueif a fair queue is being used by the connection poolbooleanReturns whether exceptions during connection creation at pool initialization should be ignored.booleanIf set to true, the connection pool creates aConnectionPoolMBeanobject that can be registered with JMX to receive notifications and state about the pool.booleanboolean flag to set if stack traces should be logged for application code which abandoned a Connection.booleanReturns true if the pool sweeper is enabled for the connection pool.booleanboolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout.booleanThe indication of whether objects will be validated before being borrowed from the pool.booleanReturns true if we should run the validation query when connecting to the database for the first time on a connection.booleanThe indication of whether objects will be validated after being returned to the pool.booleanSet to true if query validation should take place while the connection is idle.booleanSet to true if you wish theProxyConnectionclass to useString.equalsinstead of==when comparing method names.booleanReports a condition to the pool's notification listeners.voidDrops the registration name.voidpostRegister(Boolean registrationDone) Drops the registration name when the MBean server did not complete this MBean's registration.voidpreRegister(MBeanServer server, ObjectName name) voidpurge()Purges all connections in the pool.voidPurges connections when they are returned from the pool.booleanRemoves a local notification listener from the pool.voidResets the statistics of this pool: the seven counters of this interface -ConnectionPoolMBean.getBorrowedCount(),ConnectionPoolMBean.getReturnedCount(),ConnectionPoolMBean.getCreatedCount(),ConnectionPoolMBean.getReleasedCount(),ConnectionPoolMBean.getReconnectedCount(),ConnectionPoolMBean.getRemoveAbandonedCount()andConnectionPoolMBean.getReleasedIdleCount()- are brought back to zero.voidsetAbandonWhenPercentageFull(int percentage) Connections that have been abandoned (timed out) won't get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.voidsetAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) No-opvoidsetAlternateUsernameAllowed(boolean alternateUsernameAllowed) Set to true if the callgetConnection(username,password)is allowed and honored.voidsetCommitOnReturn(boolean commitOnReturn) Set to true if you want the connection pool to commit any pending transaction when a connection is returned.voidsetConnectionProperties(String connectionProperties) The properties that will be passed intoDriver.connect(String, Properties)method.voidsetDataSource(Object ds) Injects a datasource that will be used to retrieve/create connections.voidsetDataSourceJNDI(String jndiDS) Configures a JNDI name for the backing data source.voidsetDbProperties(Properties dbProperties) Replaces the whole set of database properties the pool connects with: the write is a new set rather than a change applied over the set the pool holds, and the caller owns whatever the written collection holds, asPoolProperties.setDbProperties(Properties)records.voidsetDefaultAutoCommit(Boolean defaultAutoCommit) The default auto-commit state of connections created by this pool.voidsetDefaultCatalog(String defaultCatalog) If non null, during connection creation the methodConnection.setCatalog(String)will be called with the set value.voidsetDefaultReadOnly(Boolean defaultReadOnly) If non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value.voidsetDefaultTransactionIsolation(int defaultTransactionIsolation) If set toDataSourceFactory.UNKNOWN_TRANSACTIONISOLATIONthe methodConnection.setTransactionIsolation(int)will not be called during connection creation.voidsetDriverClassName(String driverClassName) The fully qualified Java class name of the JDBC driver to be used.voidsetFairQueue(boolean fairQueue) Set to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion.voidsetIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad) Set to true if you want to ignore error of connection creation while initializing the pool.voidsetInitialSize(int initialSize) Set the number of connections that will be established when the connection pool is started.voidsetInitSQL(String initSQL) A custom query to be run when a connection is first created.voidsetJdbcInterceptors(String jdbcInterceptors) A semicolon separated list of classnames extendingJdbcInterceptorclass.voidsetJmxEnabled(boolean jmxEnabled) If set to true, the connection pool creates aConnectionPoolMBeanobject that can be registered with JMX to receive notifications and state about the pool.voidsetLogAbandoned(boolean logAbandoned) boolean flag to set if stack traces should be logged for application code which abandoned a Connection.voidsetLogValidationErrors(boolean logValidationErrors) Set to true if you wish that errors from validation should be logged as error messages.voidsetMaxActive(int maxActive) The maximum number of active connections that can be allocated from this pool at the same time.voidsetMaxAge(long maxAge) Time in milliseconds to keep this connection before reconnecting.voidsetMaxIdle(int maxIdle) The maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()returns false.voidsetMaxWait(int maxWait) The maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()has been reached) for a connection to be returned before throwing an exception.voidsetMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) The minimum amount of time an object must sit idle in the pool before it is eligible for eviction.voidsetMinIdle(int minIdle) The minimum number of established connections that should be kept in the pool at all times.voidRenames the running pool.voidsetNumTestsPerEvictionRun(int numTestsPerEvictionRun) Property not usedvoidsetPassword(String password) Sets the password on the running pool's configuration.voidsetPropagateInterruptState(boolean propagateInterruptState) Configure the pool to propagate interrupt state for interrupted threads waiting for a connection A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw aSQLExceptionreporting the interrupted wait, with theInterruptedExceptionas its cause.voidsetRemoveAbandoned(boolean removeAbandoned) boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout.voidsetRemoveAbandonedTimeout(int removeAbandonedTimeout) The time in seconds before a connection can be considered abandoned.voidsetRollbackOnReturn(boolean rollbackOnReturn) Set to true if you want the connection pool to rollback any pending transaction when a connection is returned.voidsetSuspectTimeout(int seconds) Similar toPoolConfiguration.setRemoveAbandonedTimeout(int)but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning ifPoolConfiguration.isLogAbandoned()returns true.voidsetTestOnBorrow(boolean testOnBorrow) The indication of whether objects will be validated before being borrowed from the pool.voidsetTestOnConnect(boolean testOnConnect) Set to true if we should run the validation query when connecting to the database for the first time on a connection.voidsetTestOnReturn(boolean testOnReturn) The indication of whether objects will be validated after being returned to the pool.voidsetTestWhileIdle(boolean testWhileIdle) Set to true if query validation should take place while the connection is idle.voidsetTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.voidSets the URL used to connect to the databasevoidsetUseDisposableConnectionFacade(boolean useDisposableConnectionFacade) Deprecated.The disposable connection facade is always used, so this property no longer has any effect.voidsetUseEquals(boolean useEquals) Set to true if you wish theProxyConnectionclass to useString.equalsinstead of==when comparing method names.voidsetUseLock(boolean useLock) Set to true if a lock should be used when operations are performed on the connection object.voidsetUsername(String username) Sets the user name on the running pool's configuration, with the same meaning asDataSourceProxy.setUsername(String): anulluser name takes the credential away from the database properties as well as from the configuration.voidsetUseStatementFacade(boolean useStatementFacade) Deprecated.The statement facade is always used, so this property no longer has any effect.voidsetValidationInterval(long validationInterval) avoid excess validation, only run validation at most at this frequency - time in milliseconds.voidsetValidationQuery(String validationQuery) The SQL query that will be used to validate connections from this pool before returning them to the caller or pool.voidsetValidationQueryTimeout(int validationQueryTimeout) The timeout in seconds before a connection validation queries fail.voidsetValidator(Validator validator) Sets the validator object If this is a non null object, it will be used as a validator instead of the validationQuery If this is null, remove the usage of the validator.voidsetValidatorClassName(String className) Set the name for an optional validator class which will be used in place of test queries.voidtestIdle()Runs the pass over the idle connections that validates them and takes out of the pool the ones that do not survive it.Methods inherited from class NotificationBroadcasterSupport
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
-
Field Details
-
pool
The pool this MBean wraps, assigned once by the constructor and never swapped: attribute reads consult the live configuration the pool shares with its DataSource, the operations run against this pool, and it is the pool the reported conditions describe.getPool()hands out the same reference in-process. -
sequence
sequence for JMX notifications -
listeners
Listeners that are local and interested in our notifications, no need for JMX
-
-
Constructor Details
-
ConnectionPool
Creates a new JMX wrapper for the given connection pool.- Parameters:
pool- the connection pool to wrap
-
-
Method Details
-
getPool
Returns the underlying connection pool instance.- Returns:
- the wrapped connection pool
-
getPoolProperties
Returns the pool configuration for the wrapped connection pool.- Returns:
- the pool configuration properties
-
getObjectName
Returns the JMX ObjectName under which this MBean is registered.- Returns:
- the JMX ObjectName, or
nullwhile this MBean is not registered - before its registration, after one the server has refused, and after its deregistration
-
preRegister
- Specified by:
preRegisterin interfaceMBeanRegistration- Throws:
Exception
-
postRegister
Drops the registration name when the MBean server did not complete this MBean's registration.The server calls
preRegister(MBeanServer, ObjectName)before it has looked the requested name up in its repository, so the name stored there can still be refused - the usual reason being another MBean that already holds it, most often the leftover of a pool that died without deregistering. After refusing a registration the server runs nopostDeregister(): per theMBeanRegistrationcontract afalseregistrationDonereports that the registration phase failed, which leaves this callback as the only chance to undo whatpreRegisterwrote.A name kept through a refusal is a name this MBean never acquired, and both ways it is used then act on a publication that never happened. The pool's notifications - the pool keeps running - attribute themselves to the MBean that does answer for that name, while
getNotificationSource()names the pool as a string precisely so that an MBean nobody published points at nobody else's name. And the connections, which publish themselves belowgetObjectName()as soon as their physical session is up, are offered to the server below a stranger's name: the publish either collides with the children of the MBean that owns that name - a stale pool MBean holds the very same child names - or, the child name being free, publishes a connection of this pool into a subtree this pool has no claim to and no release for, at one error log per connection. The name is also whatConnectionPool.registerConnectionMBeans()waits for, so the gate that keeps the connections of an unpublished pool unpublished opens for a name this MBean was refused. TheDataSourcethat publishes this MBean gives up its own side of a refused registration the same way.- Specified by:
postRegisterin interfaceMBeanRegistration
-
preDeregister
- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
Exception
-
postDeregister
public void postDeregister()Drops the registration name.The MBean server invokes this when the MBean is deregistered, and the pool it wraps may well keep running - a container that takes its DataSource back releases the pool MBean without closing the pool. From then on the name resolves to no MBean: notifications the pool still raises must not attribute themselves to it (see
getNotificationSource(), which falls back to naming the pool as a string), and no further MBean may be published below it.preRegister(MBeanServer, ObjectName)writes the name again if this MBean is ever registered anew.- Specified by:
postDeregisterin interfaceMBeanRegistration
-
getNotificationInfo
- Specified by:
getNotificationInfoin interfaceNotificationBroadcaster- Overrides:
getNotificationInfoin classNotificationBroadcasterSupport
-
getDefaultNotificationInfo
Returns the default notification info describing all notification types that this MBean can send.- Returns:
- array of MBeanNotificationInfo describing supported notifications
-
notify
Reports a condition to the pool's notification listeners.The delivery is asynchronous: the notification is handed to the pool's notification thread as one task, and that task delivers it - first through
NotificationBroadcasterSupport.sendNotification(Notification)to the listeners reached through JMX, then to the ones registered locally withaddListener(NotificationListener). Nothing of the delivery runs on the thread that calls this method, not even the JMX listeners' filters: the pool raises several of its notifications from the connection lifecycle, some of them while holding the lock of the connection concerned, and a monitoring listener - or a filter - that is slow or blocked must not reach those paths. The notification itself is still built on the calling thread, so it carries the time, sequence number and serializable source of the condition it reports - seegetNotificationSource()- and, since the notifier is a single thread and delivers a notification to all its listeners in one go, every listener observes the notifications one reporting thread raised in the order that thread raised them: the sequence number stamped on the calling thread records that construction order, and notifications two threads raise at the same time may be delivered in either order. A listener registered both through JMX and locally is reached through JMX before it is reached locally, as it was when delivery was synchronous.- Parameters:
type- The notification typemessage- The message- Returns:
- true if the notification was accepted for delivery as a whole, false if it was dropped as a whole - which happens when the delivery queue is full or the notification could not be built. A false means nothing was scheduled: no listener will receive this notification. The result otherwise reports the handoff only: it says nothing about whether any listener was reached or what a listener did with the notification.
-
getNotificationSource
Returns the source the pool's notifications are sent with.Notificationmarshals its source, so a listener outside this JVM - one reached through a JMX connector, or one that hands the notification on to another process - only receives the notification at all if the source is serializable. This MBean is not, and neither is the pool it wraps, so the source is theObjectNamethe MBean is registered under, which names the pool and is serializable. A pool MBean that is not registered - one that has never been registered, or one the server has taken back while its pool keeps running - has no such name: the source is then a string that names the pool.- Returns:
- the registered ObjectName, or a string naming the pool if the MBean is not registered. That fallback is a diagnostic label, not necessarily a valid ObjectName
-
addListener
Adds a local notification listener that receives pool notifications without requiring JMX registration.- Parameters:
list- the notification listener to add
-
removeListener
Removes a local notification listener from the pool.- Parameters:
list- the notification listener to remove- Returns:
trueif the listener was removed
-
getSize
public int getSize()Description copied from interface:ConnectionPoolMBeanReturns the number of connection slots the pool holds right now - the idle ones and the checked out ones together.This counts slots, not database sessions, and each of these counts reads the live state for itself. While the pool is establishing connections a slot is claimed before its session is signed on, and releasing a connection to a waiting borrower leaves a wake-up placeholder in the idle queue, so this count - and the idle count - can include an entry with no session behind it. Two of these attributes read at the same moment can still disagree: a
SizeagainstIdleplusActive, or anIdleagainst aNumIdle, is a comparison of samples taken one after the other, not of one state read once.- Specified by:
getSizein interfaceConnectionPoolMBean- Returns:
- the number of connections the pool holds a slot for
-
getIdle
public int getIdle()Description copied from interface:ConnectionPoolMBeanReturns the number of idle connections in the pool, meaning the entries that sit in the idle queue - among which there can be a wake-up placeholder with no session behind it. Like the other counts of this interface this is one sample of live state, soConnectionPoolMBean.getSize()andConnectionPoolMBean.getActive()are read separately and need not add up to it.- Specified by:
getIdlein interfaceConnectionPoolMBean- Returns:
- idle connection count
-
getActive
public int getActive()Description copied from interface:ConnectionPoolMBeanReturns the number of active (in-use) connections: the entries of the pool's busy set, which is what the pool counts as checked out rather than idle. Like the other counts of this interface this is one sample of live state, so it need not add up againstConnectionPoolMBean.getSize()andConnectionPoolMBean.getIdle(), which are read separately.- Specified by:
getActivein interfaceConnectionPoolMBean- Returns:
- active connection count
-
getNumIdle
public int getNumIdle()Description copied from interface:ConnectionPoolMBeanReturns the number of idle connections in the pool. This is another name forConnectionPoolMBean.getIdle()- the commons-dbcp naming - and reads the same count.- Specified by:
getNumIdlein interfaceConnectionPoolMBean- Returns:
- idle connection count
-
getNumActive
public int getNumActive()Description copied from interface:ConnectionPoolMBeanReturns the number of active (in-use) connections. This is another name forConnectionPoolMBean.getActive()- the commons-dbcp naming - and reads the same count.- Specified by:
getNumActivein interfaceConnectionPoolMBean- Returns:
- active connection count
-
getWaitCount
public int getWaitCount()Description copied from interface:ConnectionPoolMBeanReturns the number of threads waiting for a connection. This is the count of borrowers parked in the wait loop of the synchronousgetConnection: a caller ofgetConnectionAsyncis counted only while that call is still running, and once it has been handed a future and waits on the queue behind it, that caller is no longer counted here - the pool's own wake-up logic has to ask the queue about those waiters separately, because this counter does not see them.- Specified by:
getWaitCountin interfaceConnectionPoolMBean- Returns:
- wait count
-
getBorrowedCount
public long getBorrowedCount()Description copied from interface:ConnectionPoolMBeanReturns the total number of connections borrowed since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.- Specified by:
getBorrowedCountin interfaceConnectionPoolMBean- Returns:
- borrowed count
-
getReturnedCount
public long getReturnedCount()Description copied from interface:ConnectionPoolMBeanReturns the total number of connections returned since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent.- Specified by:
getReturnedCountin interfaceConnectionPoolMBean- Returns:
- returned count
-
getCreatedCount
public long getCreatedCount()Description copied from interface:ConnectionPoolMBeanReturns the total number of connections created since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent. This counts pooled objects the pool took into service, not sessions that came up: an attempt to establish a connection that the database refused is counted here, and its teardown is counted byConnectionPoolMBean.getReleasedCount().- Specified by:
getCreatedCountin interfaceConnectionPoolMBean- Returns:
- created count
-
getReleasedCount
public long getReleasedCount()Description copied from interface:ConnectionPoolMBeanReturns the total number of connections released since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent. This is the counterpart ofConnectionPoolMBean.getCreatedCount(): it counts each pooled object once as it goes out of service, whether or not it ever established a session.- Specified by:
getReleasedCountin interfaceConnectionPoolMBean- Returns:
- released count
-
getReconnectedCount
public long getReconnectedCount()Description copied from interface:ConnectionPoolMBeanReturns the total number of reconnections since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent. A reconnection is one session the pool replaced under a pooled object it already had: the borrower came with different credentials, the session had passed itsmaxAge, or it could not be handed out as it stood.- Specified by:
getReconnectedCountin interfaceConnectionPoolMBean- Returns:
- reconnected count
-
getRemoveAbandonedCount
public long getRemoveAbandonedCount()Description copied from interface:ConnectionPoolMBeanReturns the total number of connections removed due to abandonment since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent. Only the connections the pool actually took away are counted here; a connection that was merely marked as suspect is not counted.- Specified by:
getRemoveAbandonedCountin interfaceConnectionPoolMBean- Returns:
- abandoned count
-
getReleasedIdleCount
public long getReleasedIdleCount()Description copied from interface:ConnectionPoolMBeanReturns the total number of idle connections released since the pool was created or since the last call toConnectionPoolMBean.resetStats(), whichever is more recent. Any pass that takes an idle connection out of the pool counts here - evicting one the configuration had kept idle too long, taking back one a purge had made stale, or dropping one that did not survive the idle validation or reconnection - and that pass may be the pool cleaner working on its own timer or an explicitConnectionPoolMBean.checkIdle(),ConnectionPoolMBean.testIdle()orConnectionPoolMBean.purge()call.- Specified by:
getReleasedIdleCountin interfaceConnectionPoolMBean- Returns:
- released idle count
-
checkIdle
public void checkIdle()Description copied from interface:ConnectionPoolMBeanRuns the idle-eviction pass over the connections that are currently idle. An idle connection the configuration says should be evicted - one that has been idle pastminEvictableIdleTimeMillis, or one aConnectionPoolMBean.purgeOnReturn()orConnectionPoolMBean.purge()call made stale - is released, and the pass normally stops at theminIdlefloor. A connection a purge made stale is released regardless of that floor, so an explicit call after a purge can take the pool below it. An idle connection a borrower claims while this runs is left to that borrower. This is the pass the pool cleaner runs on its own timer, run on demand, and what it releases is counted byConnectionPoolMBean.getReleasedIdleCount().- Specified by:
checkIdlein interfaceConnectionPoolMBean
-
checkAbandoned
public void checkAbandoned()Description copied from interface:ConnectionPoolMBeanLooks through the connections that are currently checked out for ones that have been held too long. A connection past the remove-abandoned timeout is taken from its borrower and removed only whileremoveAbandonedis enabled andabandonWhenPercentageFulllets the pool's occupancy allow an abandon; each such removal is counted byConnectionPoolMBean.getRemoveAbandonedCount()and reported throughConnectionPoolMBean.NOTIFY_ABANDON. A checked-out connection that is not removed - because removal is not allowed, or because it has not passed that timeout - keeps its borrower: one held longer thansuspectTimeoutis only marked as suspect and reported throughConnectionPoolMBean.SUSPECT_ABANDONED_NOTIFICATION. WithsuspectTimeoutunset and removal off, this operation reports nothing at all.- Specified by:
checkAbandonedin interfaceConnectionPoolMBean
-
testIdle
public void testIdle()Description copied from interface:ConnectionPoolMBeanRuns the pass over the idle connections that validates them and takes out of the pool the ones that do not survive it. The validation only runs whentestWhileIdleis set; with that flag unset nothing is put to the database. Whatever the flag, a connection whosemaxAgehas expired is reconnected first, and a connection is released when that reconnection fails, when the validation runs and fails it, or when it reaches the validation with no session behind it at all. Those releases are counted byConnectionPoolMBean.getReleasedIdleCount(), and an idle connection a borrower claims while this runs is left to that borrower.- Specified by:
testIdlein interfaceConnectionPoolMBean
-
resetStats
public void resetStats()Description copied from interface:ConnectionPoolMBeanResets the statistics of this pool: the seven counters of this interface -ConnectionPoolMBean.getBorrowedCount(),ConnectionPoolMBean.getReturnedCount(),ConnectionPoolMBean.getCreatedCount(),ConnectionPoolMBean.getReleasedCount(),ConnectionPoolMBean.getReconnectedCount(),ConnectionPoolMBean.getRemoveAbandonedCount()andConnectionPoolMBean.getReleasedIdleCount()- are brought back to zero. Everything else about the pool - its connections, its configuration, its notifications - is left as it is.- Specified by:
resetStatsin interfaceConnectionPoolMBean
-
getConnectionProperties
Returns the connection properties with any credential they carry masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold. The write is not masked:setConnectionProperties(String)takes the string as it is meant to reach the driver, which is the same read/write asymmetry the password attribute has.The masked value is a display value, not a safe value to write back: the ordinary read-modify-write replaces the credential with the mask and leaves the pool unable to authenticate. Change the credential through
setPassword(String)andsetUsername(String), or read the raw value fromgetPool(). The connection properties that will be sent to the JDBC driver when establishing new connections. Format of the string is [propertyName=property;]
NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here. The default value is null.- Specified by:
getConnectionPropertiesin interfacePoolConfiguration- Returns:
- the connection properties
-
getDbProperties
Returns a copy of the database properties with the credential entries removed, so the JMX surface does not expose the plaintext password whilegetPassword()is explicitly masked. A credential entry is one whose key ispassword,passorpwd, ignoring case and surrounding whitespace. A configuration whose database properties arenull- a statePoolConfiguration.setDbProperties(Properties)accepts - has nothing to mask, so this returnsnull. Returns the database properties that are passed into theDriver.connect(String, Properties)method.The copy is a display value, and it looks complete: nothing in it says that the pool's own set carries a pair this one withholds. That matters because this attribute is also writable and its write is the whole set -
setDbProperties(Properties)replaces the live collection - so the ordinary read-modify-write of the attribute hands the pool back a set with the credential taken out and takes that credential away from the live configuration along with it. A configuration whose password travels only among the database properties - the shape the credential has when aconnectionPropertiesline carries it - then establishes its next connections with nothing to authenticate them, and nothing on the read, the write or in between warns. The credential's owning controls are thePasswordandUsernameattributes: each mirrors its value into the database properties and takes the entry away when cleared, and while one of them holds the password it, not the entry, is what new connections are established with however this attribute is written.- Specified by:
getDbPropertiesin interfacePoolConfiguration- Returns:
- database properties that are passed into the
Driver.connect(String, Properties)method, ornullwhen the configuration has none
-
getDefaultCatalog
Description copied from interface:PoolConfigurationIf non null, during connection creation the methodConnection.setCatalog(String)will be called with the set value. When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
getDefaultCatalogin interfacePoolConfiguration- Returns:
- the default catalog, null if not set and accepting the driver default.
-
getDefaultTransactionIsolation
public int getDefaultTransactionIsolation()Description copied from interface:PoolConfigurationReturns the default transaction isolation level. If set toDataSourceFactory.UNKNOWN_TRANSACTIONISOLATIONthe methodConnection.setTransactionIsolation(int)will not be called during connection creation. When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it; a level the driver refuses on a session is the one documented exception to that enforcement - the session stays in service and that level is not retried on it.- Specified by:
getDefaultTransactionIsolationin interfacePoolConfiguration- Returns:
- driver transaction isolation level, or -1
DataSourceFactory.UNKNOWN_TRANSACTIONISOLATIONif not set.
-
getDriverClassName
Description copied from interface:PoolConfigurationThe fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible from the same classloader as tomcat-jdbc.jar- Specified by:
getDriverClassNamein interfacePoolConfiguration- Returns:
- fully qualified JDBC driver name.
-
getInitialSize
public int getInitialSize()Description copied from interface:PoolConfigurationReturns the number of connections that will be established when the connection pool is started. Default value is 10- Specified by:
getInitialSizein interfacePoolConfiguration- Returns:
- number of connections to be started when pool is started
-
getInitSQL
Description copied from interface:PoolConfigurationA custom query to be run when a connection is first created. The default value is null. This query only runs once per connection, and that is when a new connection is established to the database. If this value is non null, it will replace the validation query during connection creation.The query runs while the pool is initializing the freshly established session, and the pool terminates the transaction it executes into by commit, so its effects - a data change or a session setting - persist for the lifetime of the connection even when the pool runs with auto commit off. A validation query follows the opposite rule and terminates an open transaction by rollback, so a health check never commits application work. A pool configured with a custom
Validatordoes not run this query at all: the validator replaces the validation itself.- Specified by:
getInitSQLin interfacePoolConfiguration- Returns:
- the init SQL used to run against the DB or null if not set
-
getJdbcInterceptors
Returns the interceptor configuration with any credential its definitions carry masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold - the parameter list of a definition reaches a third-party interceptor as configured, so it is one of the raw strings an operator may type a credential into. There is no write to mask:setJdbcInterceptors(String)refuses the change on a running pool at all. A semicolon separated list of classnames extendingJdbcInterceptorclass. These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object. Example interceptors areStatementFinalizerto close all used statements during the session.ResetAbandonedTimerresets the timer upon any activity on the connection, upon any statement execution and upon any read of a result set, whether the operation succeeded or failed.ConnectionStatecaches the auto commit, read only, transaction isolation and catalog settings to avoid round trips to the DB. The default value is null.- Specified by:
getJdbcInterceptorsin interfacePoolConfiguration- Returns:
- the interceptors that are used for connections. Example format: 'ConnectionState(useEquals=true,fast=yes);ResetAbandonedTimer'
-
getMaxActive
public int getMaxActive()Description copied from interface:PoolConfigurationThe maximum number of active connections that can be allocated from this pool at the same time. The default value is 100- Specified by:
getMaxActivein interfacePoolConfiguration- Returns:
- the maximum number of connections used by this pool
-
getMaxIdle
public int getMaxIdle()Description copied from interface:PoolConfigurationThe maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()returns false. IfPoolConfiguration.isPoolSweeperEnabled()returns true, then the idle pool can grow up toPoolConfiguration.getMaxActive()and will be shrunk according toPoolConfiguration.getMinEvictableIdleTimeMillis()setting. Default value isPoolConfiguration.getMaxActive()(100 with the default configuration)- Specified by:
getMaxIdlein interfacePoolConfiguration- Returns:
- the maximum number of idle connections.
-
getMaxWait
public int getMaxWait()Description copied from interface:PoolConfigurationThe maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()has been reached) for a connection to be returned before throwing an exception. A value less than or equal to zero makes the pool wait indefinitely for a connection to be returned instead of timing out. Default value is 30000 (30 seconds)- Specified by:
getMaxWaitin interfacePoolConfiguration- Returns:
- the number of milliseconds to wait for a connection to become available if the pool is maxed out.
-
getMinEvictableIdleTimeMillis
public int getMinEvictableIdleTimeMillis()Description copied from interface:PoolConfigurationThe minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).- Specified by:
getMinEvictableIdleTimeMillisin interfacePoolConfiguration- Returns:
- the minimum amount of idle time in milliseconds before a connection is considered idle and eligible for eviction.
-
getMinIdle
public int getMinIdle()Description copied from interface:PoolConfigurationThe minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. The default is the valuePoolConfiguration.getInitialSize()had when this configuration was constructed; changinginitialSizelater does not move it, so set this explicitly to change the floor (also seePoolConfiguration.setTestWhileIdle(boolean)). The eviction run normally keeps the total number of connections in the pool - idle plus busy - at or above this value, hence the number of actual connections can be betweenPoolConfiguration.getMinIdle()and somewhere betweenPoolConfiguration.getMaxIdle()andPoolConfiguration.getMaxActive(). A connection left over from an earlier pool generation is released regardless, so an explicit idle check after a purge can take the pool below the floor.- Specified by:
getMinIdlein interfacePoolConfiguration- Returns:
- the minimum number of idle or established connections
-
getMaxAge
public long getMaxAge()Description copied from interface:PoolConfigurationTime in milliseconds to keep this connection before reconnecting. When a connection is idle, returned to the pool or borrowed from the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it reconnects. Note that the age of idle connections will only be checked ifPoolConfiguration.getTimeBetweenEvictionRunsMillis()returns a value greater than 0. The default value is 0, which implies that connections will be left open and no age checks will be done. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.- Specified by:
getMaxAgein interfacePoolConfiguration- Returns:
- the time in milliseconds a connection will be open for when used
-
getName
Returns the pool's current name, as theNameattribute. This is the live configuration value and may differ from the ObjectName this MBean was registered under after a rename; seesetName(String).- Specified by:
getNamein interfacePoolConfiguration- Returns:
- the pool's current name
-
getNumTestsPerEvictionRun
public int getNumTestsPerEvictionRun()Description copied from interface:PoolConfigurationProperty not used- Specified by:
getNumTestsPerEvictionRunin interfacePoolConfiguration- Returns:
- the stored value, which the pool never reads
-
getPassword
Description copied from interface:PoolConfigurationReturns the password used when establishing connections to the database. Some implementations mask the value - theDataSourceProxyand the JMX bean return a placeholder instead of the password so that it cannot be read out through JMX - so a consumer of this contract must not treat the returned string as the configured password.- Specified by:
getPasswordin interfacePoolConfiguration- Returns:
- DOES NOT RETURN THE PASSWORD, IT WOULD SHOW UP IN JMX
-
getRemoveAbandonedTimeout
public int getRemoveAbandonedTimeout()Description copied from interface:PoolConfigurationThe time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.- Specified by:
getRemoveAbandonedTimeoutin interfacePoolConfiguration- Returns:
- the time in seconds before a used connection can be considered abandoned
- See Also:
-
getTimeBetweenEvictionRunsMillis
public int getTimeBetweenEvictionRunsMillis()Description copied from interface:PoolConfigurationThe number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)- Specified by:
getTimeBetweenEvictionRunsMillisin interfacePoolConfiguration- Returns:
- the sleep time in between validations in milliseconds
-
getUrl
Returns the JDBC URL with any credential it carries masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold. The write is not masked:setUrl(String)takes the URL as it is meant to reach the driver, which is the same read/write asymmetry the password attribute has.The masked value is a display value, not a safe value to write back: the ordinary read-modify-write replaces the credential with the mask and leaves the pool unable to authenticate. Change the credential through
setPassword(String)andsetUsername(String), or read the raw value fromgetPool(). The URL used to connect to the database- Specified by:
getUrlin interfacePoolConfiguration- Returns:
- the configured URL for this connection pool
- See Also:
-
getUsername
Description copied from interface:PoolConfigurationReturns the username used to establish the connection with- Specified by:
getUsernamein interfacePoolConfiguration- Returns:
- the username used to establish the connection with
-
getValidationInterval
public long getValidationInterval()Description copied from interface:PoolConfigurationavoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 3000 (3 seconds).- Specified by:
getValidationIntervalin interfacePoolConfiguration- Returns:
- the validation interval in milliseconds
-
getValidationQuery
Description copied from interface:PoolConfigurationThe SQL query that will be used to validate connections from this pool before returning them to the caller or pool. If specified, this query does not have to return any data, it just can't throw an SQLException. The default value is null. A blank query means the unset value: no statement, the built-inConnection.isValid(int)check runs instead. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)- Specified by:
getValidationQueryin interfacePoolConfiguration- Returns:
- the query used for validation or null if no validation is performed
-
getValidationQueryTimeout
public int getValidationQueryTimeout()Description copied from interface:PoolConfigurationThe timeout in seconds before a connection validation queries fail. A value less than or equal to zero will disable this feature. Defaults to -1.- Specified by:
getValidationQueryTimeoutin interfacePoolConfiguration- Returns:
- the timeout value in seconds
-
getValidatorClassName
Description copied from interface:PoolConfigurationReturn the name of the optional validator class - may be null.- Specified by:
getValidatorClassNamein interfacePoolConfiguration- Returns:
- the name of the optional validator class - may be null
-
getValidator
Description copied from interface:PoolConfigurationReturns the validator object used for connection validation. May be null if the pool is using a standard validation query instead.- Specified by:
getValidatorin interfacePoolConfiguration- Returns:
- the optional validator object - may be null
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()Description copied from interface:PoolConfigurationProperty not used. Access is always allowed. Access can be achieved by calling unwrap on the pooled connection. seeDataSourceinterface or call getConnection through reflection or cast the object asPooledConnection- Specified by:
isAccessToUnderlyingConnectionAllowedin interfacePoolConfiguration- Returns:
true
-
isDefaultAutoCommit
Description copied from interface:PoolConfigurationThe default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then theConnection.setAutoCommit(boolean)method will not be called.) When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
isDefaultAutoCommitin interfacePoolConfiguration- Returns:
- the default auto commit setting, null is Driver default.
-
isDefaultReadOnly
Description copied from interface:PoolConfigurationIf non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value. When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
isDefaultReadOnlyin interfacePoolConfiguration- Returns:
- null if not set and accepting the driver default otherwise the read only value
-
isLogAbandoned
public boolean isLogAbandoned()Description copied from interface:PoolConfigurationboolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.- Specified by:
isLogAbandonedin interfacePoolConfiguration- Returns:
- true if the connection pool logs stack traces when connections are borrowed from the pool.
-
isPoolSweeperEnabled
public boolean isPoolSweeperEnabled()Description copied from interface:PoolConfigurationReturns true if the pool sweeper is enabled for the connection pool. The pool sweeper is enabled if any settings that require async intervention in the pool are turned on. Implementations are expected to run the background maintenance wheneverboolean timer = getTimeBetweenEvictionRunsMillis()>0; boolean result = timer && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0); result = result || (timer && getSuspectTimeout()>0); result = result || (timer && isTestWhileIdle()); result = result || (timer && getMinEvictableIdleTimeMillis()>0); result = result || (timer && getMaxAge()>0); return result;so enabling the maintenance when any one of these triggers is turned on satisfies the contract. With the defaults shipped byPoolPropertiesthe sweeper is enabled. When it runs, the background cleaner thread checks for abandoned connections whenPoolConfiguration.isRemoveAbandoned()is set, marks and reports connections that exceededPoolConfiguration.getSuspectTimeout(), evicts idle connections towardsPoolConfiguration.getMinIdle(), validates idle connections whenPoolConfiguration.isTestWhileIdle()is set and reconnects idle connections that exceededPoolConfiguration.getMaxAge(). While the sweeper is enabled, the pool also takes the per-connection lock when borrowing and returning connections (the same lockPoolConfiguration.getUseLock()forces on) and returned connections are kept beyondPoolConfiguration.getMaxIdle(), letting the idle pool grow towardsPoolConfiguration.getMaxActive()as the cleaner trims it.- Specified by:
isPoolSweeperEnabledin interfacePoolConfiguration- Returns:
- true if a background thread is or will be enabled for this pool
-
isRemoveAbandoned
public boolean isRemoveAbandoned()Description copied from interface:PoolConfigurationboolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than thePoolConfiguration.getRemoveAbandonedTimeout()and the condition forPoolConfiguration.getAbandonWhenPercentageFull()is met. Setting this to true can recover db connections from applications that fail to close a connection. See alsoPoolConfiguration.isLogAbandoned()The default value is false.- Specified by:
isRemoveAbandonedin interfacePoolConfiguration- Returns:
- true if abandoned connections can be closed and expelled out of the pool
-
getAbandonWhenPercentageFull
public int getAbandonWhenPercentageFull()Description copied from interface:PoolConfigurationConnections that have been abandoned (timed out) won't get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.- Specified by:
getAbandonWhenPercentageFullin interfacePoolConfiguration- Returns:
- percentage - a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned
-
isTestOnBorrow
public boolean isTestOnBorrow()Description copied from interface:PoolConfigurationThe indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, a reconnection of the same pooled connection is attempted and validated again; if that also fails, the object is dropped from the pool and the borrow fails with an SQLException. NOTE - if no validationQuery is set,Connection.isValid(int)is used to validate the connection. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)- Specified by:
isTestOnBorrowin interfacePoolConfiguration- Returns:
- true if the connection is to be validated upon borrowing a connection from the pool
- See Also:
-
isTestOnConnect
public boolean isTestOnConnect()Description copied from interface:PoolConfigurationReturns true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false, unless one wants to use the validationQuery as an init query.- Specified by:
isTestOnConnectin interfacePoolConfiguration- Returns:
- true if we should run the validation query upon connect
-
isTestOnReturn
public boolean isTestOnReturn()Description copied from interface:PoolConfigurationThe indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - if no validationQuery is set,Connection.isValid(int)is used to validate the connection. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)- Specified by:
isTestOnReturnin interfacePoolConfiguration- Returns:
- true if validation should take place after a connection is returned to the pool
- See Also:
-
isTestWhileIdle
public boolean isTestWhileIdle()Description copied from interface:PoolConfigurationSet to true if query validation should take place while the connection is idle.- Specified by:
isTestWhileIdlein interfacePoolConfiguration- Returns:
- true if validation should take place during idle checks
- See Also:
-
getDefaultAutoCommit
Description copied from interface:PoolConfigurationThe default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then theConnection.setAutoCommit(boolean)method will not be called.) When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
getDefaultAutoCommitin interfacePoolConfiguration- Returns:
- the default auto commit setting, null is Driver default.
-
getDefaultReadOnly
Description copied from interface:PoolConfigurationIf non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value. When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
getDefaultReadOnlyin interfacePoolConfiguration- Returns:
- null if not set and accepting the driver default otherwise the read only value
-
getJdbcInterceptorsAsArray
Returns the parsed interceptor configuration with any credential its definitions carry masked out, so that a read of this attribute does not hand back in cleartext the passwordgetPassword()exists to withhold - the pairs of a definition reach a third-party interceptor as configured, which is whygetJdbcInterceptors()masks them in the string this attribute is the parsed form of. There is no write to mask:setJdbcInterceptors(String)refuses the change on a running pool at all. The array is a copy made for this read, so the configuration the interceptor chains are built from keeps the raw pairs and this attribute is no way to reach those definitions either. Returns thePoolConfiguration.getJdbcInterceptors()as an array of objects with properties and the classes.- Specified by:
getJdbcInterceptorsAsArrayin interfacePoolConfiguration- Returns:
- an array of interceptors that have been configured
-
getUseLock
public boolean getUseLock()Description copied from interface:PoolConfigurationReturn true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.- Specified by:
getUseLockin interfacePoolConfiguration- Returns:
- true if a lock is used.
-
isFairQueue
public boolean isFairQueue()Description copied from interface:PoolConfigurationReturnstrueif a fair queue is being used by the connection pool- Specified by:
isFairQueuein interfacePoolConfiguration- Returns:
trueif a fair waiting queue is being used
-
isJmxEnabled
public boolean isJmxEnabled()Description copied from interface:PoolConfigurationIf set to true, the connection pool creates aConnectionPoolMBeanobject that can be registered with JMX to receive notifications and state about the pool. The ConnectionPool object doesn't register itself, as there is no way to keep a static non changing ObjectName across JVM restarts.- Specified by:
isJmxEnabledin interfacePoolConfiguration- Returns:
- true if the mbean object will be created upon startup.
-
isUseEquals
public boolean isUseEquals()Description copied from interface:PoolConfigurationSet to true if you wish theProxyConnectionclass to useString.equalsinstead of==when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value istrue.- Specified by:
isUseEqualsin interfacePoolConfiguration- Returns:
- true if pool uses
String.equals(Object)instead of == when comparing method names onConnectionmethods
-
setAbandonWhenPercentageFull
public void setAbandonWhenPercentageFull(int percentage) Description copied from interface:PoolConfigurationConnections that have been abandoned (timed out) won't get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.- Specified by:
setAbandonWhenPercentageFullin interfacePoolConfiguration- Parameters:
percentage- a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned
-
setAccessToUnderlyingConnectionAllowed
public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) Description copied from interface:PoolConfigurationNo-op- Specified by:
setAccessToUnderlyingConnectionAllowedin interfacePoolConfiguration- Parameters:
accessToUnderlyingConnectionAllowed- parameter ignored
-
setDbProperties
Replaces the whole set of database properties the pool connects with: the write is a new set rather than a change applied over the set the pool holds, and the caller owns whatever the written collection holds, asPoolProperties.setDbProperties(Properties)records. It re-mirrors nothing - theuserandpasswordentries are whatever the set written here carries. The read of this same attribute,getDbProperties(), withholds the password, so writing back what that read returned - the ordinary way of adding or removing one entry - drops the credential from the live configuration: a pool whose password travels only among the database properties establishes its next connections with nothing to authenticate them, while a pool whose credential thePasswordattribute holds keeps authenticating with the attribute, the superseded entry going with the replaced set. The Password attribute and itsUsernamepair are therefore the credential's owning controls: they mirror their value into the database properties and take the entry away when cleared, whereas this attribute can only be written with a set the writer itself already holds the credential for - what the read hands back is never that set.- Specified by:
setDbPropertiesin interfacePoolConfiguration- Parameters:
dbProperties- The database properties, may benull
-
setDefaultReadOnly
Description copied from interface:PoolConfigurationIf non null, during connection creation the methodConnection.setReadOnly(boolean)will be called with the set value. When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
setDefaultReadOnlyin interfacePoolConfiguration- Parameters:
defaultReadOnly- null if not set and accepting the driver default.
-
setMaxAge
public void setMaxAge(long maxAge) Description copied from interface:PoolConfigurationTime in milliseconds to keep this connection before reconnecting. When a connection is idle, returned to the pool or borrowed from the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it reconnects. Note that the age of idle connections will only be checked ifPoolConfiguration.getTimeBetweenEvictionRunsMillis()returns a value greater than 0. The default value is 0, which implies that connections will be left open and no age checks will be done. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.- Specified by:
setMaxAgein interfacePoolConfiguration- Parameters:
maxAge- the time in milliseconds a connection will be open for when used
-
setName
Renames the running pool. The write is allowed at any time and changes only what the pool calls itself: theNameandPoolNameattributes of this MBean, the nameConnectionPool.getName()reports for the pool, and - while this MBean is not registered, so it has noObjectNameto name itself by - the string its notifications carry as their source (seegetNotificationSource()).Nothing that was registered under a name moves with the rename. Every registration made for a pool is keyed by the name the pool started with, which
ConnectionPool.getRegistrationName()returns, and not by this property: the statistics theSlowQueryReportinterceptor keeps for this pool stay reachable under the old name and are released under it when the pool closes, as does the MBean itsSlowQueryReportJmxsubclass publishes for the pool. The ObjectName this MBean is registered under is, in the same way, the one its registration took, and the per-connection MBeans stay published below that name.- Specified by:
setNamein interfacePoolConfiguration- Parameters:
name- the name the pool is to call itself by from now on
-
getPoolName
Returns the pool's current name, as thePoolNameattribute. The MBean's registration name is fixed when it is registered; a rename changes this value without moving the registration.- Specified by:
getPoolNamein interfacePoolConfiguration- Returns:
- the pool's current name
-
setConnectionProperties
Description copied from interface:PoolConfigurationThe properties that will be passed intoDriver.connect(String, Properties)method. Username and password do not need to be stored here, they will be passed into the properties right before the connection is established.Re-setting the string re-applies it: the pairs the previous value of the string contributed are removed from the driver properties before the new ones are parsed in, so a reconfigure that drops a pair really stops sending it, while entries contributed from elsewhere - the explicitly passed user and password among them - are kept. A
nullvalue clears the string and takes its contributed pairs with it.- Specified by:
setConnectionPropertiesin interfacePoolConfiguration- Parameters:
connectionProperties- properties - Format of the string is [propertyName=property;]* Example: prop1=value1;prop2=value2, may benull
-
setDefaultAutoCommit
Description copied from interface:PoolConfigurationThe default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then theConnection.setAutoCommit(boolean)method will not be called.) When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
setDefaultAutoCommitin interfacePoolConfiguration- Parameters:
defaultAutoCommit- default auto commit setting, null is Driver default.
-
setDefaultCatalog
Description copied from interface:PoolConfigurationIf non null, during connection creation the methodConnection.setCatalog(String)will be called with the set value. When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.- Specified by:
setDefaultCatalogin interfacePoolConfiguration- Parameters:
defaultCatalog- null if not set and accepting the driver default.
-
setDefaultTransactionIsolation
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) Description copied from interface:PoolConfigurationIf set toDataSourceFactory.UNKNOWN_TRANSACTIONISOLATIONthe methodConnection.setTransactionIsolation(int)will not be called during connection creation. Otherwise the method will be called with the isolation level set by this property. When theConnectionStateinterceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it (seePoolConfiguration.getDefaultTransactionIsolation()for the refused-level exception).- Specified by:
setDefaultTransactionIsolationin interfacePoolConfiguration- Parameters:
defaultTransactionIsolation- a value ofConnection.TRANSACTION_NONE,Connection.TRANSACTION_READ_COMMITTED,Connection.TRANSACTION_READ_UNCOMMITTED,Connection.TRANSACTION_REPEATABLE_READ,Connection.TRANSACTION_SERIALIZABLEorDataSourceFactory.UNKNOWN_TRANSACTIONISOLATIONThe last value will not be set on the connection.
-
setDriverClassName
Description copied from interface:PoolConfigurationThe fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible from the same classloader as tomcat-jdbc.jar- Specified by:
setDriverClassNamein interfacePoolConfiguration- Parameters:
driverClassName- a fully qualified Java class name of aDriverimplementation.
-
setFairQueue
public void setFairQueue(boolean fairQueue) Description copied from interface:PoolConfigurationSet to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion. This uses theFairBlockingQueueimplementation for the list of the idle connections. The default value is true. This flag is required when you want to use asynchronous connection retrieval.- Specified by:
setFairQueuein interfacePoolConfiguration- Parameters:
fairQueue-trueto use a fair queue- Throws:
UnsupportedOperationException- always - whether borrow waits are queued fairly is decided when the pool builds its wait queue; set the property before starting the pool
-
setInitialSize
public void setInitialSize(int initialSize) Description copied from interface:PoolConfigurationSet the number of connections that will be established when the connection pool is started. Default value is 10. If this value exceedsPoolConfiguration.setMaxActive(int)it will automatically be lowered.- Specified by:
setInitialSizein interfacePoolConfiguration- Parameters:
initialSize- the number of connections to be established.- Throws:
UnsupportedOperationException- always - the initial size is what the pool pre-loads with when it is created; set the property before starting the pool
-
setInitSQL
Description copied from interface:PoolConfigurationA custom query to be run when a connection is first created. The default value is null. This query only runs once per connection, and that is when a new connection is established to the database. If this value is non null, it will replace the validation query during connection creation.The query runs while the pool is initializing the freshly established session, and the pool terminates the transaction it executes into by commit, so its effects - a data change or a session setting - persist for the lifetime of the connection even when the pool runs with auto commit off. A validation query follows the opposite rule and terminates an open transaction by rollback, so a health check never commits application work. A pool configured with a custom
Validatordoes not run this query at all: the validator replaces the validation itself.- Specified by:
setInitSQLin interfacePoolConfiguration- Parameters:
initSQL- the init SQL used to run against the DB or null if no query should be executed
-
setJdbcInterceptors
Description copied from interface:PoolConfigurationA semicolon separated list of classnames extendingJdbcInterceptorclass. These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object. Example interceptors areStatementFinalizerto close all used statements during the session.ResetAbandonedTimerresets the timer upon any activity on the connection, upon any statement execution and upon any read of a result set, whether the operation succeeded or failed.ConnectionStatecaches the auto commit, read only, transaction isolation and catalog settings to avoid round trips to the DB. The default value is null.- Specified by:
setJdbcInterceptorsin interfacePoolConfiguration- Parameters:
jdbcInterceptors- the interceptors that are used for connections. Example format: 'ConnectionState(useEquals=true,fast=yes);ResetAbandonedTimer'- Throws:
UnsupportedOperationException- always - the interceptor chain is built when the pool starts and for every connection it establishes; set the property before starting the pool
-
setJmxEnabled
public void setJmxEnabled(boolean jmxEnabled) Description copied from interface:PoolConfigurationIf set to true, the connection pool creates aConnectionPoolMBeanobject that can be registered with JMX to receive notifications and state about the pool. The ConnectionPool object doesn't register itself, as there is no way to keep a static non changing ObjectName across JVM restarts.- Specified by:
setJmxEnabledin interfacePoolConfiguration- Parameters:
jmxEnabled- set to true if the mbean object should be created upon startup.- Throws:
UnsupportedOperationException- always - whether the pool registers this MBean at all is decided when the pool is created, and a client reaching this setter has reached an MBean whose registration is that decision; set the property before starting the pool
-
setLogAbandoned
public void setLogAbandoned(boolean logAbandoned) Description copied from interface:PoolConfigurationboolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.- Specified by:
setLogAbandonedin interfacePoolConfiguration- Parameters:
logAbandoned- set to true if stack traces should be recorded whenDataSourceProxy.getConnection()is called.
-
setMaxActive
public void setMaxActive(int maxActive) Description copied from interface:PoolConfigurationThe maximum number of active connections that can be allocated from this pool at the same time. The default value is 100- Specified by:
setMaxActivein interfacePoolConfiguration- Parameters:
maxActive- hard limit for number of managed connections by this pool
-
setMaxIdle
public void setMaxIdle(int maxIdle) Description copied from interface:PoolConfigurationThe maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()returns false. IfPoolConfiguration.isPoolSweeperEnabled()returns true, then the idle pool can grow up toPoolConfiguration.getMaxActive()and will be shrunk according toPoolConfiguration.getMinEvictableIdleTimeMillis()setting. Default value isPoolConfiguration.getMaxActive()(100 with the default configuration)- Specified by:
setMaxIdlein interfacePoolConfiguration- Parameters:
maxIdle- the maximum size of the idle pool
-
setMaxWait
public void setMaxWait(int maxWait) Description copied from interface:PoolConfigurationThe maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()has been reached) for a connection to be returned before throwing an exception. A value less than or equal to zero makes the pool wait indefinitely for a connection to be returned instead of timing out. Default value is 30000 (30 seconds)- Specified by:
setMaxWaitin interfacePoolConfiguration- Parameters:
maxWait- the maximum number of milliseconds to wait.
-
setMinEvictableIdleTimeMillis
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) Description copied from interface:PoolConfigurationThe minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).- Specified by:
setMinEvictableIdleTimeMillisin interfacePoolConfiguration- Parameters:
minEvictableIdleTimeMillis- the number of milliseconds a connection must be idle to be eligible for eviction.
-
setMinIdle
public void setMinIdle(int minIdle) Description copied from interface:PoolConfigurationThe minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. The default is the valuePoolConfiguration.getInitialSize()had when this configuration was constructed; changinginitialSizelater does not move it, so set this explicitly to change the floor (also seePoolConfiguration.setTestWhileIdle(boolean)). The eviction run normally keeps the total number of connections in the pool - idle plus busy - at or above this value, hence the number of actual connections can be betweenPoolConfiguration.getMinIdle()and somewhere betweenPoolConfiguration.getMaxIdle()andPoolConfiguration.getMaxActive(). A connection left over from an earlier pool generation is released regardless, so an explicit idle check after a purge can take the pool below the floor.- Specified by:
setMinIdlein interfacePoolConfiguration- Parameters:
minIdle- the minimum number of idle or established connections
-
setNumTestsPerEvictionRun
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) Description copied from interface:PoolConfigurationProperty not used- Specified by:
setNumTestsPerEvictionRunin interfacePoolConfiguration- Parameters:
numTestsPerEvictionRun- parameter ignored.
-
setPassword
Sets the password on the running pool's configuration. The write carries the same meaning asDataSourceProxy.setPassword(String): the credential also lives among the database properties the driver is given, and anullpassword takes it away from there as well, so that clearing it here really does stop new connections authenticating with it.No session is signed on again by the write itself, so what a rotation does to the connections the pool had already established depends on who takes such a connection up again. A borrowed one takes the new password up: the borrow compares the identity the session carries with the identity configured now and, finding them different, re-establishes that same connection under the password written here, which is the identity it keeps from then on. A connection the pool takes up on its own account - an idle one whose
maxAgehas expired - signs on again with the credential it cached for itself at its first sign-on rather than with this one, so wherever the two differ the database may refuse that reconnect; the pool retires such a connection and the next borrow is served by one established under the password set here. A rotation therefore converges without the operator doing anything, at the price of a refused sign-on or two on the renewals the pool runs by itself, and it does not leave sessions in service under a superseded credential.To stop presenting the superseded credential now rather than connection by connection, expire the sessions that still carry it:
purge()closes the idle connections at once and the busy ones as they come back, whilepurgeOnReturn()waits for each connection to come back, an idle one no sooner than it has been borrowed and returned. Whatever the pool establishes after either authenticates with the password set here.- Specified by:
setPasswordin interfacePoolConfiguration- Parameters:
password- the password, ornullto take the credential away- See Also:
-
setRemoveAbandoned
public void setRemoveAbandoned(boolean removeAbandoned) Description copied from interface:PoolConfigurationboolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than thePoolConfiguration.getRemoveAbandonedTimeout()and the condition forPoolConfiguration.getAbandonWhenPercentageFull()is met. Setting this to true can recover db connections from applications that fail to close a connection. See alsoPoolConfiguration.isLogAbandoned()The default value is false.- Specified by:
setRemoveAbandonedin interfacePoolConfiguration- Parameters:
removeAbandoned- set to true if abandoned connections can be closed and expelled out of the pool
-
setRemoveAbandonedTimeout
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) Description copied from interface:PoolConfigurationThe time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.- Specified by:
setRemoveAbandonedTimeoutin interfacePoolConfiguration- Parameters:
removeAbandonedTimeout- the time in seconds before a used connection can be considered abandoned- See Also:
-
setTestOnBorrow
public void setTestOnBorrow(boolean testOnBorrow) Description copied from interface:PoolConfigurationThe indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, a reconnection of the same pooled connection is attempted and validated again; if that also fails, the object is dropped from the pool and the borrow fails with an SQLException. NOTE - if no validationQuery is set,Connection.isValid(int)is used to validate the connection. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)- Specified by:
setTestOnBorrowin interfacePoolConfiguration- Parameters:
testOnBorrow- set to true if validation should take place before a connection is handed out to the application- See Also:
-
setTestOnConnect
public void setTestOnConnect(boolean testOnConnect) Description copied from interface:PoolConfigurationSet to true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false, unless one wants to use the validationQuery as an init query. Setting anPoolConfiguration.setInitSQL(String)will override this setting, as the init SQL will be used instead of the validation query- Specified by:
setTestOnConnectin interfacePoolConfiguration- Parameters:
testOnConnect- set to true if we should run the validation query upon connect
-
setTestOnReturn
public void setTestOnReturn(boolean testOnReturn) Description copied from interface:PoolConfigurationThe indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - if no validationQuery is set,Connection.isValid(int)is used to validate the connection. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)- Specified by:
setTestOnReturnin interfacePoolConfiguration- Parameters:
testOnReturn- true if validation should take place after a connection is returned to the pool- See Also:
-
setTestWhileIdle
public void setTestWhileIdle(boolean testWhileIdle) Description copied from interface:PoolConfigurationSet to true if query validation should take place while the connection is idle.- Specified by:
setTestWhileIdlein interfacePoolConfiguration- Parameters:
testWhileIdle- true if validation should take place during idle checks- See Also:
-
setTimeBetweenEvictionRunsMillis
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) Description copied from interface:PoolConfigurationThe number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)- Specified by:
setTimeBetweenEvictionRunsMillisin interfacePoolConfiguration- Parameters:
timeBetweenEvictionRunsMillis- the sleep time in between validations in milliseconds
-
setUrl
Description copied from interface:PoolConfigurationSets the URL used to connect to the database- Specified by:
setUrlin interfacePoolConfiguration- Parameters:
url- the configured URL for this connection pool- See Also:
-
setUseEquals
public void setUseEquals(boolean useEquals) Description copied from interface:PoolConfigurationSet to true if you wish theProxyConnectionclass to useString.equalsinstead of==when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value istrue.- Specified by:
setUseEqualsin interfacePoolConfiguration- Parameters:
useEquals- set to true if the pool should useString.equals(Object)instead of == when comparing method names onConnectionmethods
-
setUseLock
public void setUseLock(boolean useLock) Description copied from interface:PoolConfigurationSet to true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.- Specified by:
setUseLockin interfacePoolConfiguration- Parameters:
useLock- set to true if a lock should be used on connection operations
-
setUsername
Sets the user name on the running pool's configuration, with the same meaning asDataSourceProxy.setUsername(String): anulluser name takes the credential away from the database properties as well as from the configuration.What
setPassword(String)records about connections the pool had already established holds here in full, because the identity a session serves under is this user name together with that password: the borrow compares the pair the session carries with the pair configured now and re-establishes the connection under the new one, while a connection the pool renews on its own account signs on again with the pair it cached at its first sign-on and is retired when the database refuses it.purge()andpurgeOnReturn()expire the sessions that still carry the superseded user name, on demand.- Specified by:
setUsernamein interfacePoolConfiguration- Parameters:
username- the user name, ornullto take the credential away- See Also:
-
setValidationInterval
public void setValidationInterval(long validationInterval) Description copied from interface:PoolConfigurationavoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 3000 (3 seconds).- Specified by:
setValidationIntervalin interfacePoolConfiguration- Parameters:
validationInterval- the validation interval in milliseconds
-
setValidationQuery
Description copied from interface:PoolConfigurationThe SQL query that will be used to validate connections from this pool before returning them to the caller or pool. If specified, this query does not have to return any data, it just can't throw an SQLException. The default value is null. A blank query is stored as the unset value: a configuration surface that cannot express null is written empty to mean "no statement", and no statement can be blank. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)- Specified by:
setValidationQueryin interfacePoolConfiguration- Parameters:
validationQuery- the query used for validation, or null or a blank string if no validation query is set
-
setValidationQueryTimeout
public void setValidationQueryTimeout(int validationQueryTimeout) Description copied from interface:PoolConfigurationThe timeout in seconds before a connection validation queries fail. A value less than or equal to zero will disable this feature. Defaults to -1.- Specified by:
setValidationQueryTimeoutin interfacePoolConfiguration- Parameters:
validationQueryTimeout- The timeout value
-
setValidatorClassName
Description copied from interface:PoolConfigurationSet the name for an optional validator class which will be used in place of test queries. If set to null, standard validation will be used.- Specified by:
setValidatorClassNamein interfacePoolConfiguration- Parameters:
className- the name of the optional validator class
-
getSuspectTimeout
public int getSuspectTimeout()Description copied from interface:PoolConfigurationReturns the time in seconds to pass before a connection is marked an abandoned suspect. Any value lesser than or equal to 0 means the check is disabled.- Specified by:
getSuspectTimeoutin interfacePoolConfiguration- Returns:
- Returns the time in seconds to pass before a connection is marked an abandoned suspect.
-
setSuspectTimeout
public void setSuspectTimeout(int seconds) Description copied from interface:PoolConfigurationSimilar toPoolConfiguration.setRemoveAbandonedTimeout(int)but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning ifPoolConfiguration.isLogAbandoned()returns true. If this value is equal or less than 0, no suspect checking will be performed. Suspect checking only takes place if the timeout value is larger than 0 and the connection was not abandoned or if abandon check is disabled. If a connection is suspect a WARN message gets logged and a JMX notification gets sent once.- Specified by:
setSuspectTimeoutin interfacePoolConfiguration- Parameters:
seconds- - the amount of time in seconds that has to pass before a connection is marked suspect.
-
setDataSource
Description copied from interface:PoolConfigurationInjects a datasource that will be used to retrieve/create connections. If a data source is set, thePoolConfiguration.getUrl()andPoolConfiguration.getDriverClassName()methods are ignored and not used by the pool. If thePoolConfiguration.getUsername()andPoolConfiguration.getPassword()values are set, the methodDataSource.getConnection(String, String)method will be called instead of theDataSource.getConnection()method. If the data source implementsXADataSourcethe methodsXADataSource.getXAConnection()andXADataSource.getXAConnection(String,String)will be invoked. If it implementsConnectionPoolDataSourcethe methodsConnectionPoolDataSource.getPooledConnection()andConnectionPoolDataSource.getPooledConnection(String,String)will be invoked instead.- Specified by:
setDataSourcein interfacePoolConfiguration- Parameters:
ds- theDataSourceto be used for creating connections to be pooled.
-
getDataSource
Description copied from interface:PoolConfigurationReturns a datasource, if one exists that is being used to create connections. This method will return null if the pool is using aDriver- Specified by:
getDataSourcein interfacePoolConfiguration- Returns:
- the backing object - a
DataSource,XADataSourceorConnectionPoolDataSource- used for creating connections to be pooled, or null if a Driver is used.
-
setDataSourceJNDI
Description copied from interface:PoolConfigurationConfigures a JNDI name for the backing data source. Instead of injecting the object throughPoolConfiguration.setDataSource(Object), this names it. The name is resolved byDataSourceFactory, which looks it up when the pool is created through the factory and JNDI path and injects the found object throughPoolConfiguration.setDataSource(Object); after that lookup,PoolConfiguration.getDataSource()does not return null. Nothing else performs the lookup: set on a pool configured programmatically, the property never becomes a data source and the pool keeps connecting through the driver properties.- Specified by:
setDataSourceJNDIin interfacePoolConfiguration- Parameters:
jndiDS- the JNDI name of the data source to wrap
-
getDataSourceJNDI
Description copied from interface:PoolConfigurationReturns the JNDI string configured for data source usage.- Specified by:
getDataSourceJNDIin interfacePoolConfiguration- Returns:
- the JNDI string or null if not set
-
isAlternateUsernameAllowed
public boolean isAlternateUsernameAllowed()Description copied from interface:PoolConfigurationReturns true if the callgetConnection(username,password)is allowed. This is used for when the pool is used by an application accessing multiple schemas. There is a performance impact turning this option on.- Specified by:
isAlternateUsernameAllowedin interfacePoolConfiguration- Returns:
- true if
getConnection(username,password)is honored, false if it is ignored.
-
setAlternateUsernameAllowed
public void setAlternateUsernameAllowed(boolean alternateUsernameAllowed) Description copied from interface:PoolConfigurationSet to true if the callgetConnection(username,password)is allowed and honored. This is used for when the pool is used by an application accessing multiple schemas. There is a performance impact turning this option on, even when not used due to username checks.- Specified by:
setAlternateUsernameAllowedin interfacePoolConfiguration- Parameters:
alternateUsernameAllowed- - set true ifgetConnection(username,password)is honored, false if it is to be ignored.
-
setValidator
Description copied from interface:PoolConfigurationSets the validator object If this is a non null object, it will be used as a validator instead of the validationQuery If this is null, remove the usage of the validator.- Specified by:
setValidatorin interfacePoolConfiguration- Parameters:
validator- The validator object
-
setCommitOnReturn
public void setCommitOnReturn(boolean commitOnReturn) Description copied from interface:PoolConfigurationSet to true if you want the connection pool to commit any pending transaction when a connection is returned. The default value is false, as this could result in committing data. This parameter is ignored ifPoolConfiguration.setRollbackOnReturn(boolean)is also set to true. The commit is only performed when the returned connection is actually in a transaction.- Specified by:
setCommitOnReturnin interfacePoolConfiguration- Parameters:
commitOnReturn- set to true if the pool should callConnection.commit()when a connection is returned to the pool. Default is false
-
getCommitOnReturn
public boolean getCommitOnReturn()Description copied from interface:PoolConfigurationReturns whether the pool commits any pending transaction when a connection is returned. SeePoolConfiguration.setCommitOnReturn(boolean)for details.- Specified by:
getCommitOnReturnin interfacePoolConfiguration- Returns:
trueif the pool should commit when a connection is returned to it
-
setRollbackOnReturn
public void setRollbackOnReturn(boolean rollbackOnReturn) Description copied from interface:PoolConfigurationSet to true if you want the connection pool to rollback any pending transaction when a connection is returned. The default value is false, as this could result in discarding data the application has not committed. The rollback is only performed when the returned connection is actually in a transaction.- Specified by:
setRollbackOnReturnin interfacePoolConfiguration- Parameters:
rollbackOnReturn- set to true if the pool should callConnection.rollback()when a connection is returned to the pool. Default is false
-
getRollbackOnReturn
public boolean getRollbackOnReturn()Description copied from interface:PoolConfigurationReturns whether the pool rolls back any pending transaction when a connection is returned. SeePoolConfiguration.setRollbackOnReturn(boolean)for details.- Specified by:
getRollbackOnReturnin interfacePoolConfiguration- Returns:
trueif the pool should rollback when a connection is returned to it
-
setUseDisposableConnectionFacade
Deprecated.The disposable connection facade is always used, so this property no longer has any effect.Stores the value of the deprecateduseDisposableConnectionFacadeproperty. The pool always wraps the connection handle in a facade that disallows use of the connection afterConnection.close()has been called, whatever value is stored here.- Specified by:
setUseDisposableConnectionFacadein interfacePoolConfiguration- Parameters:
useDisposableConnectionFacade- the configured value, retained but without effect
-
getUseDisposableConnectionFacade
Deprecated.The disposable connection facade is always used, so this property no longer has any effect.Returns the value stored for the deprecateduseDisposableConnectionFacadeproperty. The pool always wraps the connection handle in a facade that disallows use of the connection afterConnection.close()has been called, whatever value is returned here.- Specified by:
getUseDisposableConnectionFacadein interfacePoolConfiguration- Returns:
- the configured value, retained but without effect
-
setLogValidationErrors
public void setLogValidationErrors(boolean logValidationErrors) Description copied from interface:PoolConfigurationSet to true if you wish that errors from validation should be logged as error messages.- Specified by:
setLogValidationErrorsin interfacePoolConfiguration- Parameters:
logValidationErrors- set to true to log validation errors
-
getLogValidationErrors
public boolean getLogValidationErrors()Description copied from interface:PoolConfigurationReturns true if errors that happen during validation will be logged- Specified by:
getLogValidationErrorsin interfacePoolConfiguration- Returns:
- true if errors that happen during validation will be logged
-
getPropagateInterruptState
public boolean getPropagateInterruptState()Description copied from interface:PoolConfigurationReturns true if the pool is configured to propagate interrupt state of a thread. A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw aSQLExceptionreporting the interrupted wait, with theInterruptedExceptionas its cause.- Specified by:
getPropagateInterruptStatein interfacePoolConfiguration- Returns:
- true if the pool is configured to propagate and not clear the thread interrupt state
-
setPropagateInterruptState
public void setPropagateInterruptState(boolean propagateInterruptState) Description copied from interface:PoolConfigurationConfigure the pool to propagate interrupt state for interrupted threads waiting for a connection A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw aSQLExceptionreporting the interrupted wait, with theInterruptedExceptionas its cause. If set to true, this behavior will change, while theSQLExceptionis still thrown, the threads interrupted state is still set.- Specified by:
setPropagateInterruptStatein interfacePoolConfiguration- Parameters:
propagateInterruptState- - set to true to not clear, but propagate, a threads interrupted state.
-
isIgnoreExceptionOnPreLoad
public boolean isIgnoreExceptionOnPreLoad()Description copied from interface:PoolConfigurationReturns whether exceptions during connection creation at pool initialization should be ignored. SeePoolConfiguration.setIgnoreExceptionOnPreLoad(boolean)for details.- Specified by:
isIgnoreExceptionOnPreLoadin interfacePoolConfiguration- Returns:
trueto ignore exceptions during pre-load
-
setIgnoreExceptionOnPreLoad
public void setIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad) Description copied from interface:PoolConfigurationSet to true if you want to ignore error of connection creation while initializing the pool. Set to false if you want to fail the initialization of the pool by throwing exception.- Specified by:
setIgnoreExceptionOnPreLoadin interfacePoolConfiguration- Parameters:
ignoreExceptionOnPreLoad- set to true if you want to ignore error of connection creation while initializing the pool.- Throws:
UnsupportedOperationException- always - the flag governs the preload of initial connections the pool runs when it is created; set the property before starting the pool
-
getUseStatementFacade
Deprecated.The statement facade is always used, so this property no longer has any effect.Returns the value stored for the deprecateduseStatementFacadeproperty. The pool always wraps the statements it hands out - and the result sets read from them - in a facade, whatever value is returned here.- Specified by:
getUseStatementFacadein interfacePoolConfiguration- Returns:
- the configured value, retained but without effect
-
setUseStatementFacade
Deprecated.The statement facade is always used, so this property no longer has any effect.Stores the value of the deprecateduseStatementFacadeproperty. The pool always wraps the statements it hands out - and the result sets read from them - in a facade, whatever value is stored here. That facade answersequals(),hashCode()andtoString()on closed statements, answersStatement.getConnection()with the pooled connection the statement was created from, and stops the statement and its result sets from working once that connection has been returned to the pool.- Specified by:
setUseStatementFacadein interfacePoolConfiguration- Parameters:
useStatementFacade- the configured value, retained but without effect
-
purge
public void purge()Description copied from interface:ConnectionPoolMBeanPurges all connections in the pool. For connections currently in use, these connections will be purged when returned on the pool. This call also purges connections that are idle and in the pool. To only purge used/active connections seeConnectionPoolMBean.purgeOnReturn().- Specified by:
purgein interfaceConnectionPoolMBean
-
purgeOnReturn
public void purgeOnReturn()Description copied from interface:ConnectionPoolMBeanPurges connections when they are returned from the pool. This call does not purge idle connections until they are used. To purge idle connections seeConnectionPoolMBean.purge().- Specified by:
purgeOnReturnin interfaceConnectionPoolMBean
-