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

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


Chris Hegarty wrote:
> java/lang/Thread/ThreadStateTest.java 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(ThreadStateTest.java:119)
>     at ThreadStateTest.main(ThreadStateTest.java:96)
>
> 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.
>
> http://cr.openjdk.java.net/~chegar/7021010/jdk8.webrev.00/webrev/
>
> -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.

-Alan.






More information about the core-libs-dev mailing list