ILock

Interface for locks used to synchronize work or parallel processes and to prevent collisions.

Description

The ILock interface provides the methods to create locks used to synchronize work or parallel processes and to prevent collisions.

Important points

  • The interface allows to manage multiple locks identified by unique keys.

Instance methods

acquireLock

Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.

void acquireLock(IContext context, String key, int ttl, long timeout) throws InterruptedException, ApplicationException

  • context: IContext - (optional) a context to trace execution through call chain.
  • key: String - a unique lock key to acquire.
  • ttl: int - a lock timeout (time to live) in milliseconds.
  • timeout: long - a lock acquisition timeout.

tryAcquireLock

Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.

boolean tryAcquireLock(IContext context, String key, int ttl)

  • context: IContext - (optional) a context to trace execution through call chain.
  • key: String - a unique lock key to acquire.
  • ttl: int - a lock timeout (time to live) in milliseconds.
  • return: boolean - lock result

releaseLock

Releases prevously acquired lock by its key.

void releaseLock(IContext context, String key)

  • context: IContext - (optional) a context to trace execution through call chain.
  • key: String - a unique lock key to release.