Fix #125 add java version check around ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy() for Java 6.

pull/126/head
Brett Wooldridge 11 years ago
parent 5e75b12a99
commit 22f86cce82

@ -1,6 +1,6 @@
HikariCP Changes
Changes between 1.4.0 and 2.0.0
Changes between 1.4.0 and 2.0.1
* Split project into Java 6/7 and Java 8 components.

@ -51,6 +51,9 @@ import com.zaxxer.hikari.util.ConcurrentBag.IBagStateListener;
import com.zaxxer.hikari.util.DefaultThreadFactory;
import com.zaxxer.hikari.util.DriverDataSource;
import com.zaxxer.hikari.util.PropertyBeanSetter;
import static com.zaxxer.hikari.util.PoolUtilities.IS_JAVA7;
import static com.zaxxer.hikari.util.ConcurrentBag.STATE_IN_USE;
import static com.zaxxer.hikari.util.ConcurrentBag.STATE_NOT_IN_USE;
/**
* This is the primary connection pool class that provides the basic
@ -143,7 +146,9 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
long delayPeriod = Long.getLong("com.zaxxer.hikari.housekeeping.periodMs", TimeUnit.SECONDS.toMillis(30L));
houseKeepingExecutorService = new ScheduledThreadPoolExecutor(1, configuration.getThreadFactory() != null ? configuration.getThreadFactory() : new DefaultThreadFactory("Hikari Housekeeping Timer (pool " + configuration.getPoolName() + ")", true));
houseKeepingExecutorService.setRemoveOnCancelPolicy(true);
if (IS_JAVA7) {
houseKeepingExecutorService.setRemoveOnCancelPolicy(true);
}
houseKeepingExecutorService.scheduleAtFixedRate(new HouseKeeper(), delayPeriod, delayPeriod, TimeUnit.MILLISECONDS);
}
@ -339,7 +344,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
@Override
public int getIdleConnections()
{
return connectionBag.getCount(ConcurrentBag.STATE_NOT_IN_USE);
return connectionBag.getCount(STATE_NOT_IN_USE);
}
/** {@inheritDoc} */
@ -360,7 +365,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
@Override
public void closeIdleConnections()
{
for (IHikariConnectionProxy connectionProxy : connectionBag.values(ConcurrentBag.STATE_NOT_IN_USE)) {
for (IHikariConnectionProxy connectionProxy : connectionBag.values(STATE_NOT_IN_USE)) {
if (connectionBag.reserve(connectionProxy)) {
closeConnection(connectionProxy);
}
@ -476,7 +481,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
private void abortActiveConnections() throws InterruptedException
{
ExecutorService assassinExecutor = createThreadPoolExecutor(configuration.getMaximumPoolSize(), "HikariCP connection assassin", configuration.getThreadFactory());
for (IHikariConnectionProxy connectionProxy : connectionBag.values(ConcurrentBag.STATE_IN_USE)) {
for (IHikariConnectionProxy connectionProxy : connectionBag.values(STATE_IN_USE)) {
try {
connectionProxy.abort(assassinExecutor);
}
@ -484,7 +489,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
quietlyCloseConnection(connectionProxy);
}
catch (SQLException e) {
continue;
quietlyCloseConnection(connectionProxy);
}
finally {
totalConnections.decrementAndGet();
@ -553,7 +558,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
final long now = System.currentTimeMillis();
final long idleTimeout = configuration.getIdleTimeout();
for (IHikariConnectionProxy connectionProxy : connectionBag.values(ConcurrentBag.STATE_NOT_IN_USE)) {
for (IHikariConnectionProxy connectionProxy : connectionBag.values(STATE_NOT_IN_USE)) {
if (connectionBag.reserve(connectionProxy)) {
if ((idleTimeout > 0L && now > connectionProxy.getLastAccess() + idleTimeout) || (now > connectionProxy.getExpirationTime())) {
closeConnection(connectionProxy);
@ -567,8 +572,8 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
logPoolState("After cleanup ");
if (configuration.getMinimumIdle() > 0) {
addBagItem(); // Try to maintain minimum connections
}
addBagItem(); // Try to maintain minimum connections
}
}
}
}

@ -51,6 +51,8 @@ import com.zaxxer.hikari.util.ConcurrentBag.IBagStateListener;
import com.zaxxer.hikari.util.DefaultThreadFactory;
import com.zaxxer.hikari.util.DriverDataSource;
import com.zaxxer.hikari.util.PropertyBeanSetter;
import static com.zaxxer.hikari.util.ConcurrentBag.STATE_IN_USE;
import static com.zaxxer.hikari.util.ConcurrentBag.STATE_NOT_IN_USE;
/**
* This is the primary connection pool class that provides the basic
@ -333,7 +335,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
@Override
public int getIdleConnections()
{
return (int) connectionBag.getCount(ConcurrentBag.STATE_NOT_IN_USE);
return (int) connectionBag.getCount(STATE_NOT_IN_USE);
}
/** {@inheritDoc} */
@ -354,7 +356,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
@Override
public void closeIdleConnections()
{
connectionBag.values(ConcurrentBag.STATE_NOT_IN_USE).forEach(connectionProxy -> {
connectionBag.values(STATE_NOT_IN_USE).forEach(connectionProxy -> {
if (connectionBag.reserve(connectionProxy)) {
closeConnection(connectionProxy);
}
@ -468,7 +470,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
private void abortActiveConnections() throws InterruptedException
{
ExecutorService assassinExecutor = createThreadPoolExecutor(configuration.getMaximumPoolSize(), "HikariCP connection assassin", configuration.getThreadFactory());
connectionBag.values(ConcurrentBag.STATE_IN_USE).parallelStream().forEach(connectionProxy -> {
connectionBag.values(STATE_IN_USE).parallelStream().forEach(connectionProxy -> {
try {
connectionProxy.abort(assassinExecutor);
}
@ -542,7 +544,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
final long now = System.currentTimeMillis();
final long idleTimeout = configuration.getIdleTimeout();
connectionBag.values(ConcurrentBag.STATE_NOT_IN_USE).forEach(connectionProxy -> {
connectionBag.values(STATE_NOT_IN_USE).forEach(connectionProxy -> {
if (connectionBag.reserve(connectionProxy)) {
if ((idleTimeout > 0L && now > connectionProxy.getLastAccess() + idleTimeout) || (now > connectionProxy.getExpirationTime())) {
closeConnection(connectionProxy);

Loading…
Cancel
Save