keeping change in state/value of member internal

pull/374/head
Nitin 10 years ago
parent 05a4193b38
commit 7efb9c0c57

@ -454,8 +454,7 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener
void closeConnection(final PoolBagEntry bagEntry, final String closureReason)
{
final Connection connection = bagEntry.connection;
bagEntry.connection = null;
bagEntry.cancelMaxLifeTermination();
bagEntry.close();
if (connectionBag.remove(bagEntry)) {
final int tc = totalConnections.decrementAndGet();
if (tc < 0) {
@ -546,7 +545,7 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener
poolElf.quietlyCloseConnection(bagEntry.connection, "(connection aborted during shutdown)");
}
finally {
bagEntry.connection = null;
bagEntry.close();
if (connectionBag.remove(bagEntry)) {
totalConnections.decrementAndGet();
}

@ -166,9 +166,16 @@ public final class PoolBagEntry implements IConcurrentBagEntry
/** {@inheritDoc} */
@Override
public AtomicInteger state()
public int getState()
{
return state;
return state.get();
}
/** {@inheritDoc} */
@Override
public boolean compareAndSet(int expect, int update)
{
return state.compareAndSet(expect, update);
}
/** {@inheritDoc} */
@ -179,13 +186,14 @@ public final class PoolBagEntry implements IConcurrentBagEntry
connection, formatDateTime(creationTime), ClockSource.INSTANCE.elapsedMillis(lastAccess), stateToString());
}
void cancelMaxLifeTermination()
void close()
{
if (endOfLife != null && !endOfLife.isDone() && !endOfLife.cancel(false)) {
LOGGER.warn("{} - maxLifeTime expiration task cancellation unexpectedly returned false for connection {}", parentPool.config.getPoolName(), connection);
}
endOfLife = null;
connection = null;
parentPool.houseKeepingExecutorService.purge();
}

@ -21,7 +21,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -73,7 +72,8 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
int STATE_REMOVED = -1;
int STATE_RESERVED = -2;
AtomicInteger state();
boolean compareAndSet(int from, int to);
int getState();
}
public interface IBagStateListener
@ -129,7 +129,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
for (int i = list.size() - 1; i >= 0; i--) {
final T bagEntry = (T) (weakThreadLocals ? ((WeakReference) list.remove(i)).get() : list.remove(i));
if (bagEntry != null && bagEntry.state().compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
if (bagEntry != null && bagEntry.compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
return bagEntry;
}
}
@ -145,7 +145,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
do {
startSeq = synchronizer.currentSequence();
for (final T bagEntry : sharedList) {
if (bagEntry.state().compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
if (bagEntry.compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
return bagEntry;
}
}
@ -173,7 +173,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
@SuppressWarnings("unchecked")
public void requite(final T bagEntry)
{
if (bagEntry.state().compareAndSet(STATE_IN_USE, STATE_NOT_IN_USE)) {
if (bagEntry.compareAndSet(STATE_IN_USE, STATE_NOT_IN_USE)) {
final List threadLocalList = threadList.get();
if (threadLocalList != null) {
threadLocalList.add((weakThreadLocals ? new WeakReference<>(bagEntry) : bagEntry));
@ -213,7 +213,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
*/
public boolean remove(final T bagEntry)
{
if (!bagEntry.state().compareAndSet(STATE_IN_USE, STATE_REMOVED) && !bagEntry.state().compareAndSet(STATE_RESERVED, STATE_REMOVED) && !closed) {
if (!bagEntry.compareAndSet(STATE_IN_USE, STATE_REMOVED) && !bagEntry.compareAndSet(STATE_RESERVED, STATE_REMOVED) && !closed) {
LOGGER.warn("Attempt to remove an object from the bag that was not borrowed or reserved: {}", bagEntry);
return false;
}
@ -247,7 +247,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
{
final ArrayList<T> list = new ArrayList<>(sharedList.size());
for (final T reference : sharedList) {
if (reference.state().get() == state) {
if (reference.getState() == state) {
list.add(reference);
}
}
@ -283,7 +283,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
*/
public boolean reserve(final T bagEntry)
{
return bagEntry.state().compareAndSet(STATE_NOT_IN_USE, STATE_RESERVED);
return bagEntry.compareAndSet(STATE_NOT_IN_USE, STATE_RESERVED);
}
/**
@ -294,7 +294,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
*/
public void unreserve(final T bagEntry)
{
if (bagEntry.state().compareAndSet(STATE_RESERVED, STATE_NOT_IN_USE)) {
if (bagEntry.compareAndSet(STATE_RESERVED, STATE_NOT_IN_USE)) {
synchronizer.signal();
}
else {
@ -323,7 +323,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
{
int count = 0;
for (final T reference : sharedList) {
if (reference.state().get() == state) {
if (reference.getState() == state) {
count++;
}
}

Loading…
Cancel
Save