consistency cleanup, renamed requite and releaseConnection to recycle

pull/670/head
Nitin 9 years ago
parent 1f46d5f920
commit 9a868bd4b0

@ -131,7 +131,7 @@ It is a boolean value.
&#8986;``connectionTimeout``<br/>
This property controls the maximum number of milliseconds that a client (that's you) will wait
for a connection from the pool. If this time is exceeded without a connection becoming
available, a SQLException will be thrown. 1000ms is the minimum value.
available, a SQLException will be thrown. Lowest acceptable connection timeout is 250 ms.
*Default: 30000 (30 seconds)*
&#8986;``idleTimeout``<br/>
@ -254,14 +254,13 @@ class such as ``TRANSACTION_READ_COMMITTED``, ``TRANSACTION_REPEATABLE_READ``, e
&#8986;``validationTimeout``<br/>
This property controls the maximum amount of time that a connection will be tested for aliveness.
This value must be less than the ``connectionTimeout``. The lowest accepted validation timeout is
1000ms (1 second).
This value must be less than the ``connectionTimeout``. Lowest acceptable validation timeout is 250 ms.
*Default: 5000*
&#8986;``leakDetectionThreshold``<br/>
This property controls the amount of time that a connection can be out of the pool before a
message is logged indicating a possible connection leak. A value of 0 means leak detection
is disabled. Lowest acceptable value for enabling leak detection is 2000 (2 secs).
is disabled. Lowest acceptable value for enabling leak detection is 2000 (2 seconds).
*Default: 0*
&#10145;``dataSource``<br/>

@ -104,6 +104,8 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
this.totalConnections = new AtomicInteger();
this.suspendResumeLock = config.isAllowPoolSuspension() ? new SuspendResumeLock() : SuspendResumeLock.FAUX_LOCK;
checkFailFast();
if (config.getMetricsTrackerFactory() != null) {
setMetricsTrackerFactory(config.getMetricsTrackerFactory());
}
@ -115,8 +117,6 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
registerMBeans(this);
checkFailFast();
ThreadFactory threadFactory = config.getThreadFactory();
this.addConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), poolName + " connection adder", threadFactory, new ThreadPoolExecutor.DiscardPolicy());
this.closeConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), poolName + " connection closer", threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
@ -204,11 +204,10 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
softEvictConnections();
if (addConnectionExecutor != null) {
addConnectionExecutor.shutdown();
addConnectionExecutor.awaitTermination(5L, SECONDS);
}
if (config.getScheduledExecutorService() == null && houseKeepingExecutorService != null) {
if (config.getScheduledExecutorService() == null) {
houseKeepingExecutorService.shutdown();
houseKeepingExecutorService.awaitTermination(5L, SECONDS);
}
@ -230,11 +229,10 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
}
shutdownNetworkTimeoutExecutor();
if (closeConnectionExecutor != null) {
closeConnectionExecutor.shutdown();
closeConnectionExecutor.awaitTermination(5L, SECONDS);
}
}
finally {
logPoolState("After closing ");
unregisterMBeans();
@ -383,16 +381,16 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
}
/**
* Release a connection back to the pool, or permanently close it if it is broken.
* Recycle PoolEntry (add back to the pool)
*
* @param poolEntry the PoolBagEntry to release back to the pool
* @param poolEntry the PoolEntry to recycle
*/
@Override
final void releaseConnection(final PoolEntry poolEntry)
final void recycle(final PoolEntry poolEntry)
{
metricsTracker.recordConnectionUsage(poolEntry);
connectionBag.requite(poolEntry);
connectionBag.recycle(poolEntry);
}
/**
@ -506,13 +504,6 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
newConnection().close();
}
catch (Throwable e) {
try {
shutdown();
}
catch (Throwable ex) {
e.addSuppressed(ex);
}
throw new PoolInitializationException(e);
}
}
@ -520,13 +511,10 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
private void softEvictConnection(final PoolEntry poolEntry, final String reason, final boolean owner)
{
if (owner || connectionBag.reserve(poolEntry)) {
poolEntry.markEvicted();
if (owner || connectionBag.reserve(poolEntry)) {
closeConnection(poolEntry, reason);
}
else {
poolEntry.markEvicted();
}
}
private PoolStats getPoolStats()
@ -609,7 +597,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
// Detect retrograde time, allowing +128ms as per NTP spec.
if (clockSource.plusMillis(now, 128) < clockSource.plusMillis(previous, HOUSEKEEPING_PERIOD_MS)) {
LOGGER.warn("{} - Retrograde clock change detected (housekeeper delta={}), soft-evicting connections from pool.",
clockSource.elapsedDisplayString(previous, now), poolName);
poolName, clockSource.elapsedDisplayString(previous, now));
previous = now;
softEvictConnections();
fillPool();
@ -617,7 +605,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
}
else if (now > clockSource.plusMillis(previous, (3 * HOUSEKEEPING_PERIOD_MS) / 2)) {
// No point evicting for forward clock motion, this merely accelerates connection retirement anyway
LOGGER.warn("{} - Thread starvation or clock leap detected (housekeeper delta={}).", clockSource.elapsedDisplayString(previous, now), poolName);
LOGGER.warn("{} - Thread starvation or clock leap detected (housekeeper delta={}).", poolName, clockSource.elapsedDisplayString(previous, now));
}
previous = now;

@ -98,7 +98,7 @@ abstract class PoolBase
return poolName;
}
abstract void releaseConnection(final PoolEntry poolEntry);
abstract void recycle(final PoolEntry poolEntry);
// ***********************************************************************
// JDBC methods
@ -239,7 +239,7 @@ abstract class PoolBase
mBeanServer.registerMBean(hikariPool, beanPoolName);
}
else {
LOGGER.error("{} - You cannot use the same pool name for separate pool instances.", poolName);
LOGGER.error("{} - is already registered.", poolName);
}
}
catch (Exception e) {
@ -265,6 +265,9 @@ abstract class PoolBase
mBeanServer.unregisterMBean(beanConfigName);
mBeanServer.unregisterMBean(beanPoolName);
}
else {
LOGGER.error("{} - is not registered.", poolName);
}
}
catch (Exception e) {
LOGGER.warn("{} - Failed to unregister management beans.", poolName, e);
@ -299,7 +302,7 @@ abstract class PoolBase
}
if (dataSource != null) {
setLoginTimeout(dataSource, connectionTimeout);
setLoginTimeout(dataSource);
createNetworkTimeoutExecutor(dataSource, dsClassName, jdbcUrl);
}
@ -370,24 +373,18 @@ abstract class PoolBase
private void checkDriverSupport(final Connection connection) throws SQLException
{
if (!isValidChecked) {
if (isUseJdbc4Validation) {
try {
if (isUseJdbc4Validation) {
connection.isValid(1);
}
catch (Throwable e) {
LOGGER.error("{} - Failed to execute isValid() for connection, configure connection test query. ({})", poolName, e.getMessage());
throw e;
}
}
else {
try {
executeSql(connection, config.getConnectionTestQuery(), false);
}
}
catch (Throwable e) {
LOGGER.error("{} - Failed to execute connection test query. ({})", poolName, e.getMessage());
LOGGER.error("{} - Failed to execute" + (isUseJdbc4Validation ? " isValid() for connection, configure" : "") + " connection test query. ({})", poolName, e.getMessage());
throw e;
}
}
defaultTransactionIsolation = connection.getTransactionIsolation();
if (transactionIsolation == -1) {
@ -441,7 +438,7 @@ abstract class PoolBase
if (isNetworkTimeoutSupported == UNINITIALIZED) {
isNetworkTimeoutSupported = FALSE;
LOGGER.info("{} - Driver does not support get/set network timeout for connections. ({})", poolName, e.getMessage());
LOGGER.info("{} - Failed to get/set network timeout for connection. ({})", poolName, e.getMessage());
if (validationTimeout < SECONDS.toMillis(1)) {
LOGGER.warn("{} - A validationTimeout of less than 1 second cannot be honored on drivers without setNetworkTimeout() support.", poolName);
}
@ -519,9 +516,8 @@ abstract class PoolBase
* Set the loginTimeout on the specified DataSource.
*
* @param dataSource the DataSource
* @param connectionTimeout the timeout in milliseconds
*/
private void setLoginTimeout(final DataSource dataSource, final long connectionTimeout)
private void setLoginTimeout(final DataSource dataSource)
{
if (connectionTimeout != Integer.MAX_VALUE) {
try {

@ -84,7 +84,7 @@ final class PoolEntry implements IConcurrentBagEntry
{
if (connection != null) {
this.lastAccessed = lastAccessed;
hikariPool.releaseConnection(this);
hikariPool.recycle(this);
}
}

@ -140,7 +140,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
// Otherwise, scan the shared list ... for maximum of timeout
timeout = timeUnit.toNanos(timeout);
Future<Boolean> addItemFuture = null;
final long startScan = System.nanoTime();
final long startTime = System.nanoTime();
final long originTimeout = timeout;
long startSeq;
waiters.incrementAndGet();
@ -165,7 +165,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
addItemFuture = listener.addBagItem();
}
timeout = originTimeout - (System.nanoTime() - startScan);
timeout = originTimeout - (System.nanoTime() - startTime);
} while (timeout > 10_000L && synchronizer.waitUntilSequenceExceeded(startSeq, timeout));
}
finally {
@ -177,14 +177,14 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
/**
* This method will return a borrowed object to the bag. Objects
* that are borrowed from the bag but never "requited" will result
* that are borrowed from the bag but never "recycled" will result
* in a memory leak.
*
* @param bagEntry the value to return to the bag
* @throws NullPointerException if value is null
* @throws IllegalStateException if the requited value was not borrowed from the bag
* @throws IllegalStateException if the bagEntry was not borrowed from the bag
*/
public void requite(final T bagEntry)
public void recycle(final T bagEntry)
{
bagEntry.lazySet(STATE_NOT_IN_USE);

Loading…
Cancel
Save