Skip to content

Commit

Permalink
Fixes brettwooldridge#880 Fix race condition caused by sorting collec…
Browse files Browse the repository at this point in the history
…tion

while the condition of sort can change.
  • Loading branch information
brettwooldridge authored and kollstrom committed Feb 4, 2021
1 parent d035ba2 commit f74a103
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/main/java/com/zaxxer/hikari/util/ConcurrentBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -76,7 +76,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab

private final SynchronousQueue<T> handoffQueue;

public static interface IConcurrentBagEntry
public interface IConcurrentBagEntry
{
int STATE_NOT_IN_USE = 0;
int STATE_IN_USE = 1;
Expand All @@ -88,9 +88,9 @@ public static interface IConcurrentBagEntry
int getState();
}

public static interface IBagStateListener
public interface IBagStateListener
{
Future<Boolean> addBagItem(int waiting);
void addBagItem(int waiting);
}

/**
Expand Down Expand Up @@ -262,7 +262,9 @@ public void close()
*/
public List<T> values(final int state)
{
return sharedList.stream().filter(e -> e.getState() == state).collect(Collectors.toList());
final List<T> list = sharedList.stream().filter(e -> e.getState() == state).collect(Collectors.toList());
Collections.reverse(list);
return list;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
*/
public class ConnectionPoolSizeVsThreadsTest {

public static final Logger LOGGER = LoggerFactory.getLogger(ConnectionPoolSizeVsThreadsTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionPoolSizeVsThreadsTest.class);

public static final int ITERATIONS = 50_000;
private static final int ITERATIONS = 50_000;

@Test
public void testPoolSizeAboutSameSizeAsThreadCount() throws Exception {
Expand Down

0 comments on commit f74a103

Please sign in to comment.