removed check (claimed != null) from hotpath

pull/459/head
Nitin 10 years ago
parent aa06e6d26d
commit 5ac346be79

@ -49,7 +49,6 @@ import com.zaxxer.hikari.util.ConcurrentBag.IBagStateListener;
import com.zaxxer.hikari.util.DefaultThreadFactory;
import com.zaxxer.hikari.util.SuspendResumeLock;
import static com.zaxxer.hikari.pool.PoolEntry.MAXED_POOL_MARKER;
import static com.zaxxer.hikari.util.ConcurrentBag.IConcurrentBagEntry.STATE_IN_USE;
import static com.zaxxer.hikari.util.ConcurrentBag.IConcurrentBagEntry.STATE_NOT_IN_USE;
import static com.zaxxer.hikari.util.ConcurrentBag.IConcurrentBagEntry.STATE_REMOVED;
@ -567,7 +566,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
long sleepBackoff = 200L;
do {
final PoolEntry poolEntry = createPoolEntry();
if (poolEntry == MAXED_POOL_MARKER) {
if (poolEntry == PoolEntry.MAXED_POOL_MARKER) {
return Boolean.FALSE;
}
else if (poolEntry != null) {

@ -127,9 +127,18 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
public T borrow(long timeout, final TimeUnit timeUnit) throws InterruptedException
{
// Try the thread-local list first
T claimed = claimFromThreadLocal();
if (claimed != null) {
return claimed;
List<?> list = threadList.get();
if (weakThreadLocals && list == null) {
list = new ArrayList<>(16);
threadList.set(list);
}
for (int i = list.size() - 1; i >= 0; i--) {
@SuppressWarnings("unchecked")
final T bagEntry = (T) (weakThreadLocals ? ((WeakReference) list.remove(i)).get() : list.remove(i));
if (bagEntry != null && bagEntry.compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
return bagEntry;
}
}
// Otherwise, scan the shared list ... for maximum of timeout
@ -355,25 +364,6 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
}
}
private T claimFromThreadLocal()
{
List<?> list = threadList.get();
if (weakThreadLocals && list == null) {
list = new ArrayList<>(16);
threadList.set(list);
}
for (int i = list.size() - 1; i >= 0; i--) {
@SuppressWarnings("unchecked")
final T bagEntry = (T) (weakThreadLocals ? ((WeakReference) list.remove(i)).get() : list.remove(i));
if (bagEntry != null && bagEntry.compareAndSet(STATE_NOT_IN_USE, STATE_IN_USE)) {
return bagEntry;
}
}
return null;
}
/**
* Determine whether to use WeakReferences based on whether there is a
* custom ClassLoader implementation sitting between this class and the

Loading…
Cancel
Save