void (int L, int N) { boolean[] indexMask = new boolean[L]; int[] indicesToSet = new Random().ints(L / 2, 0, L).peek(i->indexMask[i]=true).toArray(); long distinctIndexNumber = Arrays.stream(indicesToSet).distinct().count(); ExecutorService executor = create4ThreadsExecutor(); try { Set<Thread> threadUsed = ConcurrentCollectionFactory.createConcurrentSet(); Semaphore threadReady = new Semaphore(); for (int it = 0; it < N; it++) { ConcurrentBitSet bitSet = ConcurrentBitSet.create(); assertEquals(-1, bitSet.nextSetBit(0)); boundedParallelRun(executor, threadUsed, threadReady, L, i -> { bitSet.set(i); assertTrue(bitSet.get(i)); }); assertEquals(L, bitSet.nextClearBit(0)); boundedParallelRun(executor, threadUsed, threadReady, L, i -> { bitSet.clear(i); assertFalse(bitSet.get(i)); }); assertEquals(-1, bitSet.nextSetBit(0)); boundedParallelRun(executor, threadUsed, threadReady, L / 2, i -> bitSet.set(indicesToSet[i])); assertEquals(distinctIndexNumber, bitSet.cardinality()); boundedParallelRun(executor, threadUsed, threadReady, L, i -> { assertEquals(indexMask[i], bitSet.get(i)); bitSet.set(i); }); boundedParallelRun(executor, threadUsed, threadReady, L / 2, i -> bitSet.clear(indicesToSet[i])); assertEquals(distinctIndexNumber, L-bitSet.cardinality()); boundedParallelRun(executor, threadUsed, threadReady, L, i -> { assertEquals(!indexMask[i], bitSet.get(i)); }); bitSet.clear(); assertEquals(-1, bitSet.nextSetBit(0)); } System.out.println("threadUsed = " + threadUsed); } finally { executor.shutdownNow(); } }