void () { int n = 100; final List<String> callTrace = new ArrayList<>(); TestDataService[] dataServiceArray = new TestDataService[n]; for (int i = 0; i < n; i++) { dataServiceArray[i] = new TestDataService(callTrace); } maskProjectDataServices(dataServiceArray); final CountDownLatch latch = new CountDownLatch(1); final Ref<Throwable> caughtCME = new Ref<>(null); Thread iterating = new Thread(() -> { await(latch); try { List<ProjectDataService<?, ?>> services = ProjectDataManagerImpl.getInstance().findService(TestDataService.TEST_KEY); for (ProjectDataService<?, ?> service : services) { Thread.yield(); } } catch (ConcurrentModificationException e) { caughtCME.set(e); } }, "Iterating over services"); Thread lookup = new Thread(() -> { await(latch); try { for (int i = 0; i < n; i++) { Thread.yield(); ProjectDataManagerImpl.getInstance().findService(TestDataService.TEST_KEY); } } catch (ConcurrentModificationException e) { caughtCME.set(e); } }, "Lookup service with sorting"); iterating.start(); lookup.start(); latch.countDown(); ConcurrencyUtil.joinAll(iterating, lookup); assertNull(caughtCME.get()); }