Class DataLocker

java.lang.Object
com.usatiuk.utils.DataLocker

public class DataLocker extends Object
Allows to lock arbitrary keys.
  • Constructor Details

    • DataLocker

      public DataLocker()
  • Method Details

    • lock

      @Nonnull public AutoCloseableNoThrow lock(Object data)
      Locks the data and returns an AutoCloseable that unlocks it when closed.
      Parameters:
      data - the data to lock
      Returns:
      an AutoCloseable that unlocks the data when closed
    • tryLock

      @Nullable public AutoCloseableNoThrow tryLock(Object data)
      Tries to lock the data and returns an AutoCloseable that unlocks it when closed. If the lock is not acquired, returns null.
      Parameters:
      data - the data to lock
      Returns:
      an AutoCloseable that unlocks the data when closed, or null if the lock was not acquired