/** Removes all of the mappings from this map. */ @Override public void clear() { // Smack a new empty table down Object[] newkvs = new NonBlockingIdentityHashMap(MIN_SIZE)._kvs; while( !CAS_kvs(_kvs,newkvs) ) // Spin until the clear works ; }
@BeforeClass public static void setUp() { _nbhm = new NonBlockingIdentityHashMap<>(); }
public NonBlockingIdentityHashMap<Long, TestKey> getMapMultithreaded() throws InterruptedException, ExecutionException { final int threadCount = _items.keySet().size(); final NonBlockingIdentityHashMap<Long, TestKey> map = new NonBlockingIdentityHashMap<>(); // use a barrier to open the gate for all threads at once to avoid rolling start and no actual concurrency final CyclicBarrier barrier = new CyclicBarrier(threadCount); final ExecutorService ex = Executors.newFixedThreadPool(threadCount); final CompletionService<Integer> co = new ExecutorCompletionService<>(ex); for (Integer type : _items.keySet()) { // A linked-list of things to insert List<TestKey> items = _items.get(type); TestKeyFeederThread feeder = new TestKeyFeederThread(items, map, barrier); co.submit(feeder); } // wait for all threads to return int itemCount = 0; for (int retCount = 0; retCount < threadCount; retCount++) { final Future<Integer> result = co.take(); itemCount += result.get(); } ex.shutdown(); return map; } }
@Test public void testConcurrentSimple() throws InterruptedException final NonBlockingIdentityHashMap<String, String> nbhm = new NonBlockingIdentityHashMap<>(); final String[] keys = new String[20000]; for (int i = 0; i < 20000; i++)
final int ITEM_COUNT = PER_CNT * THREAD_COUNT; // fix roundoff for odd thread counts NonBlockingIdentityHashMap<Long, TestKey> nbhml = new NonBlockingIdentityHashMap<>();
@Test public void testIterationBig2() { final int CNT = 10000; NonBlockingIdentityHashMap<Integer, String> nbhm = new NonBlockingIdentityHashMap<>(); final String v = "v"; for (int i = 0; i < CNT; i++) { final Integer z = i; String s0 = nbhm.get(z); assertThat(s0, nullValue()); nbhm.put(z, v); String s1 = nbhm.get(z); assertThat(s1, is(v)); } assertThat(nbhm.size(), is(CNT)); _nbhm.clear(); }
@Test public final void testNonBlockingIdentityHashMapSize() NonBlockingIdentityHashMap<Long, String> items = new NonBlockingIdentityHashMap<>(); items.put(100L, "100"); items.put(101L, "101");
NonBlockingIdentityHashMap<KeyBonk, String> dumb = new NonBlockingIdentityHashMap<>(); for (int i = 0; i < 10000; i++)
/** Removes all of the mappings from this map. */ @Override public void clear() { // Smack a new empty table down Object[] newkvs = new NonBlockingIdentityHashMap(MIN_SIZE)._kvs; while( !CAS_kvs(_kvs,newkvs) ) // Spin until the clear works ; }