Code Review 7021010: java/lang/Thread/ fails intermittently

Alan Bateman Alan.Bateman at
Mon Jun 20 19:31:31 UTC 2011

Chris Hegarty wrote:
> java/lang/Thread/ can fail with when 
> checkThreadState finds an unexpected state.
> Exception in thread "main" java.lang.RuntimeException: MyThread 
> expected to have TERMINATED but got RUNNABLE
>     at ThreadStateTest.checkThreadState(
>     at ThreadStateTest.main(
> There is a race between the thread being put in a specific state and 
> the thread testing for that state. The test should retry the thread 
> state check a number of times before failing. Also, some minor cleanup 
> and update to use a more recent j.u.c reusable synchronization barrier.
> -Chris.
The retry loop in checkThreadState make sense. Is the 100ms sleep a bit 
excessive? The thread will likely get to the expected state in a 
fraction of that time.

One question on the TERMINATED state. Given that the check is now moved 
to after the join then could this be a simple getState check rather than 
using checkThreadState?

The clean-up to use Phaser looks good to me.


More information about the core-libs-dev mailing list