Class Workers
Centralizes the two termination patterns used across sinks, UI, and retry paths:
awaitExecutorShutdown(ExecutorService, long)forExecutorServiceowners (cancel queued work, wait briefly for in-flight tasks to exit).awaitThreadJoin(Thread, long)for rawThreadowners (interrupt the worker, wait briefly for it to exit its run loop).
Both helpers are no-ops on null, swallow no other exceptions, and restore the
current thread's interrupt flag when the wait is interrupted. Callers are expected to have
already swapped the owning reference to null under their own lock so lazy restart
(on the next write) is the path forward after shutdown.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault maximum millisecondsawaitExecutorShutdown(java.util.concurrent.ExecutorService, long)andawaitThreadJoin(java.lang.Thread, long)callers wait for termination before returning. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidawaitExecutorShutdown(ExecutorService executor, long timeoutMs) Cancels queued work and waits briefly forexecutorto terminate.static voidawaitThreadJoin(Thread worker, long timeoutMs) Interruptsworkerand waits briefly for it to exit.
-
Field Details
-
DEFAULT_SHUTDOWN_TIMEOUT_MS
public static final long DEFAULT_SHUTDOWN_TIMEOUT_MSDefault maximum millisecondsawaitExecutorShutdown(java.util.concurrent.ExecutorService, long)andawaitThreadJoin(java.lang.Thread, long)callers wait for termination before returning.One second matches the historical per-owner budget used across sinks, UI, and retry paths. Chosen to keep extension unload responsive while still giving in-flight work a reasonable window to exit. Exposed as a single source of truth so every
LazySchedulerand every rawExecutorServiceowner agrees on the same shutdown semantics.- See Also:
-
-
Method Details
-
awaitExecutorShutdown
Cancels queued work and waits briefly forexecutorto terminate.Invokes
ExecutorService.shutdownNow()and thenExecutorService.awaitTermination(long, TimeUnit)fortimeoutMsmilliseconds. If the wait is interrupted, the current thread's interrupt flag is restored and the method returns without throwing.- Parameters:
executor- executor to stop; ignored whennulltimeoutMs- maximum milliseconds to wait for termination; values<= 0only request cancellation without waiting
-
awaitThreadJoin
Interruptsworkerand waits briefly for it to exit.Invokes
Thread.interrupt()and thenThread.join(long)fortimeoutMsmilliseconds. If the wait is interrupted, the current thread's interrupt flag is restored and the method returns without throwing.- Parameters:
worker- thread to stop; ignored whennulltimeoutMs- maximum milliseconds to wait forjoin; values<= 0only signal interrupt without waiting
-