Minor cleanup.

pull/77/head
Brett Wooldridge 11 years ago
parent 12d9de5cfe
commit 719da54897

@ -37,9 +37,9 @@ public class HikariConfig implements HikariConfigMBean
{
private static final Logger LOGGER = LoggerFactory.getLogger(HikariConfig.class);
private static final long CONNECTION_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
private static final long IDLE_TIMEOUT = TimeUnit.MINUTES.toMillis(10);
private static final long MAX_LIFETIME = TimeUnit.MINUTES.toMillis(30);
private static final long CONNECTION_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
private static final long IDLE_TIMEOUT = TimeUnit.MINUTES.toMillis(10);
private static final long MAX_LIFETIME = TimeUnit.MINUTES.toMillis(30);
private static int poolNumber;
@ -77,7 +77,6 @@ public class HikariConfig implements HikariConfigMBean
private Properties dataSourceProperties;
private int transactionIsolation;
static
{
JavassistProxyFactory.initialize();
@ -112,7 +111,6 @@ public class HikariConfig implements HikariConfigMBean
PropertyBeanSetter.setTargetFromProperties(this, properties);
}
/**
* Construct a HikariConfig from the specified property file name.
*
@ -130,7 +128,7 @@ public class HikariConfig implements HikariConfigMBean
try
{
FileInputStream fis = new FileInputStream(propFile);
FileInputStream fis = new FileInputStream(propFile);
Properties props = new Properties();
props.load(fis);
PropertyBeanSetter.setTargetFromProperties(this, props);
@ -315,7 +313,7 @@ public class HikariConfig implements HikariConfigMBean
{
return this.dataSourceJndiName;
}
public void setDataSourceJNDI(String jndiDataSource)
{
this.dataSourceJndiName = jndiDataSource;
@ -477,7 +475,7 @@ public class HikariConfig implements HikariConfigMBean
@Override
public void setLeakDetectionThreshold(long leakDetectionThresholdMs)
{
this.leakDetectionThreshold = leakDetectionThresholdMs;
this.leakDetectionThreshold = leakDetectionThresholdMs;
}
@Deprecated
@ -735,17 +733,20 @@ public class HikariConfig implements HikariConfigMBean
void copyState(HikariConfig other)
{
for (Field field : HikariConfig.class.getDeclaredFields())
{
if (!Modifier.isFinal(field.getModifiers()))
{
field.setAccessible(true);
try {
field.set(other, field.get(this));
} catch (Exception e) {
throw new RuntimeException("Exception copying HikariConfig state: " + e.getMessage(), e);
}
}
}
for (Field field : HikariConfig.class.getDeclaredFields())
{
if (!Modifier.isFinal(field.getModifiers()))
{
field.setAccessible(true);
try
{
field.set(other, field.get(this));
}
catch (Exception e)
{
throw new RuntimeException("Exception copying HikariConfig state: " + e.getMessage(), e);
}
}
}
}
}

@ -53,9 +53,9 @@ public class HikariDataSource extends HikariConfig implements DataSource
*/
public HikariDataSource()
{
super();
fastPathPool = null;
multiPool = new HashMap<MultiPoolKey, HikariPool>();
super();
fastPathPool = null;
multiPool = new HashMap<MultiPoolKey, HikariPool>();
}
/**
@ -66,10 +66,10 @@ public class HikariDataSource extends HikariConfig implements DataSource
public HikariDataSource(HikariConfig configuration)
{
configuration.validate();
configuration.copyState(this);
configuration.copyState(this);
multiPool = new HashMap<MultiPoolKey, HikariPool>();
pool = fastPathPool = new HikariPool(this);
multiPool.put(new MultiPoolKey(getUsername(), getPassword()), pool);
pool = fastPathPool = new HikariPool(this);
multiPool.put(new MultiPoolKey(getUsername(), getPassword()), pool);
}
/** {@inheritDoc} */
@ -80,27 +80,27 @@ public class HikariDataSource extends HikariConfig implements DataSource
{
throw new SQLException("Pool has been shutdown");
}
if (fastPathPool != null)
{
return fastPathPool.getConnection();
return fastPathPool.getConnection();
}
// See http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
HikariPool result = pool;
if (result == null)
{
synchronized (this)
{
result = pool;
if (result == null)
{
validate();
pool = result = new HikariPool(this);
multiPool.put(new MultiPoolKey(getUsername(), getPassword()), pool);
}
}
}
if (result == null)
{
synchronized (this)
{
result = pool;
if (result == null)
{
validate();
pool = result = new HikariPool(this);
multiPool.put(new MultiPoolKey(getUsername(), getPassword()), pool);
}
}
}
return result.getConnection();
}
@ -232,7 +232,7 @@ public class HikariDataSource extends HikariConfig implements DataSource
{
LoggerFactory.getLogger(getClass()).warn("Interrupted during shutdown", e);
}
if (pool.getDataSource() instanceof DriverDataSource)
{
((DriverDataSource) pool.getDataSource()).shutdown();

@ -196,8 +196,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
}
/**
* Release a connection back to the pool, or permanently close it if it
* is broken.
* Release a connection back to the pool, or permanently close it if it is broken.
*
* @param connectionProxy the connection to release back to the pool
*/
@ -297,22 +296,13 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
{
int sleepBackoff = 200;
final int maxPoolSize = configuration.getMaximumPoolSize();
while (totalConnections.get() < maxPoolSize)
final int minIdle = configuration.getMinimumIdle();
while (totalConnections.get() < maxPoolSize && (minIdle == 0 || getIdleConnections() < minIdle))
{
final int minIdle = configuration.getMinimumIdle();
if (minIdle != 0 && getIdleConnections() >= minIdle)
{
break;
}
else if (!addConnection())
if (!addConnection())
{
PoolUtilities.quietlySleep(sleepBackoff);
sleepBackoff = (int) Math.min(1000f, ((float) sleepBackoff) * 1.5);
if (getThreadsAwaitingConnection() == 0)
{
lastConnectionFailure.set(null);
break;
}
continue;
}

Loading…
Cancel
Save