Java micro-library for writing & testing concurrent code

Thread Conditions

Wait for a Thread to be in a State

Conditions.isWaiting(Thread thread)

A Condition that allows you to test if a thread is in a waiting state. For example,

waitOrTimeout(isWaiting(thread), timeout(seconds(10)));

Conditions.is(Thread thread, Thread.State state)

A more general purpose Condition to check that a thread is in a given state. For example,

waitOrTimeout(is(thread, TERMINATED), timeout(seconds(10)));

Conditions.isAlive(Thread thread)

Checks that a thread is alive. A thread is alive if it has been started and has not yet died. For example,


Wait for an Executor to Shutdown

Conditions.shutdown(ExecutorService service)

Checks that a java.util.concurrent.ExecutorService has been shutdown according to the result of the it's isShutdown method. This might be useful if you'd like to wait for shutdown. The tempus-fugit ExecutorServiceShutdown class does just this.

waitOrTimeout(Conditions.shutdown(executor), timeout);

Invert a Condition

Conditions.not(Condition condition)

The NotCondition will negate the logical result of some other condition. For example, we can change the example above to wait until a thread is not in a waiting state by using the following.

waitOrTimeout(not(isWaiting(thread)), timeout(seconds(10)));

Next, Thread Utilities: Miscellaneous »