Interface LockingTaskExecutorListener
LockingTaskExecutor lifecycle events. Implementations receive callbacks at
each stage of lock acquisition and task execution.
Exception safety: Implementations may throw without affecting lock management.
DefaultLockingTaskExecutor wraps every callback in a safeEmit guard that catches
and logs exceptions, ensuring listener failures never prevent a lock from being released.
Single-listener limitation: DefaultLockingTaskExecutor accepts exactly one
listener. To combine multiple listeners (e.g. Micrometer metrics plus custom tracing), compose
them manually before passing to the executor.
Reentrant execution: When a task re-enters the executor for the same lock on the same
thread, onTaskStarted(LockConfiguration) and onTaskFinished(LockConfiguration, Duration) are called for the inner execution,
but onLockAttempt(LockConfiguration) and onLockAcquired(LockConfiguration) are not — the lock is already
held. Implementations that track execution counts will therefore observe more onTaskStarted
events than onLockAcquired events in reentrant scenarios.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LockingTaskExecutorListenerNo-op implementation, used as the default when no listener is configured. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidonLockAcquired(LockConfiguration lockConfig) Called after the lock is successfully acquired.default voidonLockAttempt(LockConfiguration lockConfig) Called before attempting to acquire the lock.default voidonLockNotAcquired(LockConfiguration lockConfig) Called when the lock could not be acquired (another node holds it).default voidonTaskFinished(LockConfiguration lockConfig, Duration executionTime) Called after the task body finishes, whether it completed normally or threw an exception.default voidonTaskStarted(LockConfiguration lockConfig) Called immediately before the task body begins executing.
-
Field Details
-
NO_OP
No-op implementation, used as the default when no listener is configured.
-
-
Method Details
-
onLockAttempt
Called before attempting to acquire the lock. Not called for reentrant executions of the same lock on the same thread. -
onLockAcquired
Called after the lock is successfully acquired. Not called for reentrant executions of the same lock on the same thread. -
onLockNotAcquired
Called when the lock could not be acquired (another node holds it). The task will not be executed. -
onTaskStarted
Called immediately before the task body begins executing. Called for both initial and reentrant executions. -
onTaskFinished
Called after the task body finishes, whether it completed normally or threw an exception. Called for both initial and reentrant executions.- Parameters:
executionTime- wall-clock duration of the task body (excluding lock acquisition time)
-