void () { try { while (currentThreadPageIndex < pagesCreated.length) { if (currentThreadPageIndex == sharedPageIndexBarrier.get()) { pagesCreatedByThread[currentThreadPageIndex] = pages.lookupOrCreate( currentThreadPageIndex, pagesFactory ); final int threadsAlreadyFinishedWithPage = threadsOnBarrier.incrementAndGet(); //the last thread to come to the barrier -- moves the barrier farther: if (threadsAlreadyFinishedWithPage == threads.length) { threadsOnBarrier.set(0); sharedPageIndexBarrier.incrementAndGet(); } currentThreadPageIndex++; } } } catch (IOException e) { errorHolder.set(e); } }