Delay execution until the previous task is completed with the balking pattern
Sometimes it is required to consider the task state changes to properly execute next task and fulfill the goal.
Motivation
Although the instance mutability is not a desirable state, especially not in the concurrency field the ability to depend on the object state may come handy. The case where multiple threads try to acquire an object to execute its critical sections can be limited by the object state. The state can decide whether the processing time will be used or not in order to coordinate the resources available. For example, a vehicle cannot stop without being in motion.
Sample code
Consider the example of one Vehicle
instance sharing two groups of drivers. Although there are multiple groups, only one vehicle can operate at a time (Example 6.6):
public static void main(String[] args) throws Exception { System.out.println("Balking pattern, vehicle move"...