public class ShutdownLatch extends Object
registerActivity(). A registered activity should always shutdown through the returned ShutdownLatch.ActivityHandle's
ShutdownLatch.ActivityHandle.end() method once it has completed. Otherwise initiateShutdown() will block
indefinitely. If the latch is waited on through initiateShutdown(), new operations can no longer be
registered.| Modifier and Type | Class and Description |
|---|---|
class |
ShutdownLatch.ActivityHandle
A handle for an activity registered to a
ShutdownLatch. |
| Constructor and Description |
|---|
ShutdownLatch() |
| Modifier and Type | Method and Description |
|---|---|
void |
ifShuttingDown(String exceptionMessage)
Check whether this
ShutdownLatch is shutting down. |
void |
ifShuttingDown(Supplier<RuntimeException> exceptionSupplier)
Check whether this
ShutdownLatch is shutting down. |
void |
initialize()
Initialize this
ShutdownLatch. |
CompletableFuture<Void> |
initiateShutdown()
Initiate the shutdown of this latch.
|
boolean |
isShuttingDown()
Check whether this
ShutdownLatch is shutting down. |
ShutdownLatch.ActivityHandle |
registerActivity()
Add an activity this latch should wait on before opening up.
|
public void initialize()
ShutdownLatch. If the latch was already closed through initiateShutdown(), then
that operation will be canceled.public ShutdownLatch.ActivityHandle registerActivity()
initiateShutdown() has already been called a ShutdownInProgressException will be thrown.ShutdownLatch.ActivityHandle to ShutdownLatch.ActivityHandle.end() the registered activity once it is doneShutdownInProgressException - if initiateShutdown() has been called prior to invoking this methodpublic void ifShuttingDown(String exceptionMessage)
ShutdownLatch is shutting down. The given exceptionMessage is used in the
thrown ShutdownInProgressException, if this latch is shutting down.exceptionMessage - the message used for the ShutdownInProgressException to throw if this latch is
shutting downpublic void ifShuttingDown(Supplier<RuntimeException> exceptionSupplier)
ShutdownLatch is shutting down. The exception retrieved from the exceptionSupplier will be thrown if this latch is shutting down.exceptionSupplier - a Supplier of a RuntimeException to throw if this latch is waited onpublic boolean isShuttingDown()
ShutdownLatch is shutting down.true if the latch is waited on, false otherwisepublic CompletableFuture<Void> initiateShutdown()
CompletableFuture will complete once all activities
have been ended or complete immediately if no activities are active.CompletableFuture which completes once all activities are doneCopyright © 2010–2023. All rights reserved.