docs: add explanation for balking pattern (#1685)
* #590 explanation for balking pattern * #590 fix checkstyle error Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
This commit is contained in:
@ -32,11 +32,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* then the method will return without doing anything. Objects that use this pattern are generally
|
||||
* only in a state that is prone to balking temporarily but for an unknown amount of time
|
||||
*
|
||||
* <p>In this example implementation WashingMachine is an object that has two states in which it
|
||||
* can be: ENABLED and WASHING. If the machine is ENABLED the state is changed into WASHING that any
|
||||
* other thread can't invoke this action on this and then do the job. On the other hand if it have
|
||||
* been already washing and any other thread execute wash() it can't do that once again and returns
|
||||
* doing nothing.
|
||||
* <p>In this example implementation, {@link WashingMachine} is an object that has two states in
|
||||
* which it can be: ENABLED and WASHING. If the machine is ENABLED, the state changes to WASHING
|
||||
* using a thread-safe method. On the other hand, if it already has been washing and any other
|
||||
* thread executes {@link WashingMachine#wash()} it won't do that and returns without doing
|
||||
* anything.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
@ -54,11 +54,12 @@ public class App {
|
||||
}
|
||||
executorService.shutdown();
|
||||
try {
|
||||
executorService.awaitTermination(10, TimeUnit.SECONDS);
|
||||
if (!executorService.awaitTermination(10, TimeUnit.SECONDS)) {
|
||||
executorService.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
LOGGER.error("ERROR: Waiting on executor service shutdown!");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user