concurrentunit
concurrentunit copied to clipboard
Facilitate starting threads' work at the same time
As you yourself apparently noted at https://www.planetgeek.ch/2009/08/25/how-to-find-a-concurrency-bug-with-java/ :
This pattern looks similar to what was generalized into the ConcurrentUnit library for testing multi-threaded code
But there's one thing missing, this part from the article:
// wait until all threads are ready
assertTrue("Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent", allExecutorThreadsReady.await(runnables.size() * 10, TimeUnit.MILLISECONDS));
// start all test runners
afterInitBlocker.countDown();
Waiting for threads' actual readiness would maximize test's chances at revealing concurrency problems.
A Waiter could certainly be used to wait for threads to be ready, or anything else. Each resume() call on a Waiter is similar to a countDown() on a CountdownLatch.