public class ComponentClosingUtils extends Object
Modifier and Type | Method and Description |
---|---|
static CompletableFuture<Void> |
closeAsyncWithTimeout(String componentName,
Runnable closingSequence,
Duration closeTimeout)
Close a component with a timeout.
|
static CompletableFuture<Void> |
closeAsyncWithTimeout(String componentName,
ThrowingRunnable<Exception> closingSequence,
Duration closeTimeout)
Close a component with a timeout.
|
static boolean |
shutdownExecutorForcefully(ExecutorService executor,
Duration timeout)
Shutdown the given executor forcefully within the given timeout.
|
static boolean |
shutdownExecutorForcefully(ExecutorService executor,
Duration timeout,
boolean interruptable)
Shutdown the given executor forcefully within the given timeout.
|
static boolean |
tryShutdownExecutorElegantly(ExecutorService executor,
Duration timeout)
A util method that tries to shut down an
ExecutorService elegantly within the given
timeout. |
public static CompletableFuture<Void> closeAsyncWithTimeout(String componentName, Runnable closingSequence, Duration closeTimeout)
componentName
- the name of the component.closingSequence
- the closing logic which is a callable that can throw exceptions.closeTimeout
- the timeout to wait for the component to close.public static CompletableFuture<Void> closeAsyncWithTimeout(String componentName, ThrowingRunnable<Exception> closingSequence, Duration closeTimeout)
componentName
- the name of the component.closingSequence
- the closing logic.closeTimeout
- the timeout to wait for the component to close.public static boolean tryShutdownExecutorElegantly(ExecutorService executor, Duration timeout)
ExecutorService
elegantly within the given
timeout. If the executor has not been shut down before it hits timeout or the thread is
interrupted when waiting for the termination, a forceful shutdown will be attempted on the
executor.executor
- the ExecutorService
to shut down.timeout
- the timeout duration.public static boolean shutdownExecutorForcefully(ExecutorService executor, Duration timeout)
executor
- the executor to shut down.timeout
- the timeout duration.public static boolean shutdownExecutorForcefully(ExecutorService executor, Duration timeout, boolean interruptable)
executor
- the executor to shut down.timeout
- the timeout duration.interruptable
- when set to true, the method can be interrupted. Each interruption to
the thread results in another ExecutorService.shutdownNow()
call to the shutting
down executor.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.