More clean-up/tighten-up of code.

pull/84/head
Brett Wooldridge 11 years ago
parent bebe95b504
commit 275aeeb19c

@ -40,7 +40,9 @@ public class HikariDataSource extends HikariConfig implements DataSource
{
private static final Logger LOGGER = LoggerFactory.getLogger(HikariDataSource.class);
// We use a concrete HashMap rather than Map to avoid an invokeinterface callsite
private final HashMap<MultiPoolKey, HikariPool> multiPool;
private volatile boolean isShutdown;
private int loginTimeout;
@ -228,49 +230,39 @@ public class HikariDataSource extends HikariConfig implements DataSource
isShutdown = true;
if (pool != null)
{
try
if (fastPathPool != null)
{
pool.shutdown();
}
catch (InterruptedException e)
{
LoggerFactory.getLogger(getClass()).warn("Interrupted during shutdown", e);
shutdownHelper(fastPathPool);
}
if (pool.getDataSource() instanceof DriverDataSource)
for (HikariPool hikariPool : multiPool.values())
{
((DriverDataSource) pool.getDataSource()).shutdown();
shutdownHelper(hikariPool);
}
}
if (!multiPool.isEmpty())
/** {@inheritDoc} */
@Override
public String toString()
{
for (HikariPool hikariPool : multiPool.values())
return String.format("HikariDataSource (%s)", pool);
}
private void shutdownHelper(HikariPool hPool)
{
try
{
hikariPool.shutdown();
hPool.shutdown();
}
catch (InterruptedException e)
{
LoggerFactory.getLogger(getClass()).warn("Interrupted during shutdown", e);
}
if (hikariPool.getDataSource() instanceof DriverDataSource)
if (hPool.getDataSource() instanceof DriverDataSource)
{
((DriverDataSource) hikariPool.getDataSource()).shutdown();
}
}
}
((DriverDataSource) hPool.getDataSource()).shutdown();
}
/** {@inheritDoc} */
@Override
public String toString()
{
return String.format("HikariDataSource (%s)", pool);
}
private static class MultiPoolKey

@ -440,8 +440,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
{
return connection.isValid((int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs));
}
else
{
Statement statement = connection.createStatement();
try
{
@ -454,16 +453,14 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
finally
{
statement.close();
}
if (isIsolateInternalQueries && !isAutoCommit)
{
connection.rollback();
}
}
return true;
}
}
catch (SQLException e)
{
LOGGER.warn("Exception during keep alive check, that means the connection must be dead.", e);
@ -620,10 +617,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
logPoolState("After cleanup ");
if (getIdleConnections() < configuration.getMinimumIdle() && totalConnections.get() < configuration.getMaximumPoolSize())
{
addBagItem(); // Try to maintain minimum connections
}
}
}
}

@ -322,18 +322,20 @@ public class ConcurrentBag<T extends com.zaxxer.hikari.util.ConcurrentBag.IBagMa
private static class Synchronizer extends AbstractQueuedLongSynchronizer
{
private static final long serialVersionUID = 104753538004341218L;
private static boolean JAVA7;
private static final boolean JAVA7;
static
{
boolean b = false;
try
{
JAVA7 = AbstractQueuedLongSynchronizer.class.getMethod("hasQueuedPredecessors", new Class<?>[0]) != null;
b = AbstractQueuedLongSynchronizer.class.getMethod("hasQueuedPredecessors", new Class<?>[0]) != null;
}
catch (Exception e)
{
// nothing
}
JAVA7 = b;
}
@Override

@ -27,7 +27,6 @@ import java.lang.reflect.Array;
public final class FastList<T>
{
private T[] elementData;
private int size;
/**
@ -60,8 +59,7 @@ public final class FastList<T>
{
try
{
elementData[size] = element;
size++;
elementData[size++] = element;
}
catch (ArrayIndexOutOfBoundsException e)
{
@ -71,7 +69,7 @@ public final class FastList<T>
@SuppressWarnings("unchecked")
final T[] newElementData = (T[]) Array.newInstance(element.getClass(), newCapacity);
System.arraycopy(elementData, 0, newElementData, 0, oldCapacity);
newElementData[size++] = element;
newElementData[size - 1] = element;
elementData = newElementData;
}
}

@ -11,18 +11,20 @@ import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
public final class PoolUtilities
{
public static boolean IS_JAVA7;
public static final boolean IS_JAVA7;
static
{
boolean b = false;
try
{
IS_JAVA7 = AbstractQueuedLongSynchronizer.class.getMethod("hasQueuedPredecessors", new Class<?>[0]) != null;
b = AbstractQueuedLongSynchronizer.class.getMethod("hasQueuedPredecessors", new Class<?>[0]) != null;
}
catch (Exception e)
{
IS_JAVA7 = false;
}
IS_JAVA7 = b;
}
public static void quietlyCloseConnection(Connection connection)
@ -119,7 +121,7 @@ public final class PoolUtilities
int processors = Math.max(1, Runtime.getRuntime().availableProcessors() / 2);
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(queueSize);
ThreadPoolExecutor executor = new ThreadPoolExecutor(processors, processors, 10, TimeUnit.SECONDS, queue, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
ThreadPoolExecutor executor = new ThreadPoolExecutor(processors, processors, 2, TimeUnit.SECONDS, queue, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
executor.allowCoreThreadTimeOut(true);
return executor;
}

Loading…
Cancel
Save