concurrentunit icon indicating copy to clipboard operation
concurrentunit copied to clipboard

Facilitate starting threads' work at the same time

Open VsevolodGolovanov opened this issue 7 years ago • 1 comments

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.

VsevolodGolovanov avatar Feb 15 '19 15:02 VsevolodGolovanov

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.

jhalterman avatar Jul 26 '19 03:07 jhalterman