Interface LockingTaskExecutorListener


public interface LockingTaskExecutorListener
Listener for 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 Details

  • Method Details

    • onLockAttempt

      default void onLockAttempt(LockConfiguration lockConfig)
      Called before attempting to acquire the lock. Not called for reentrant executions of the same lock on the same thread.
    • onLockAcquired

      default void onLockAcquired(LockConfiguration lockConfig)
      Called after the lock is successfully acquired. Not called for reentrant executions of the same lock on the same thread.
    • onLockNotAcquired

      default void onLockNotAcquired(LockConfiguration lockConfig)
      Called when the lock could not be acquired (another node holds it). The task will not be executed.
    • onTaskStarted

      default void onTaskStarted(LockConfiguration lockConfig)
      Called immediately before the task body begins executing. Called for both initial and reentrant executions.
    • onTaskFinished

      default void onTaskFinished(LockConfiguration lockConfig, Duration executionTime)
      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)