Interface RLock

    • Method Detail

      • getName

        String getName()
        Returns name of object
        Returns:
        name - name of object
      • lockInterruptibly

        void lockInterruptibly​(long leaseTime,
                               TimeUnit unit)
                        throws InterruptedException
        Acquires the lock with defined leaseTime. Waits if necessary until lock became available. Lock will be released automatically after defined leaseTime interval.
        Parameters:
        leaseTime - the maximum time to hold the lock after it's acquisition, if it hasn't already been released by invoking unlock. If leaseTime is -1, hold the lock until explicitly unlocked.
        unit - the time unit
        Throws:
        InterruptedException - - if the thread is interrupted
      • tryLock

        boolean tryLock​(long waitTime,
                        long leaseTime,
                        TimeUnit unit)
                 throws InterruptedException
        Tries to acquire the lock with defined leaseTime. Waits up to defined waitTime if necessary until the lock became available. Lock will be released automatically after defined leaseTime interval.
        Parameters:
        waitTime - the maximum time to acquire the lock
        leaseTime - lease time
        unit - time unit
        Returns:
        true if lock is successfully acquired, otherwise false if lock is already set.
        Throws:
        InterruptedException - - if the thread is interrupted
      • lock

        void lock​(long leaseTime,
                  TimeUnit unit)
        Acquires the lock with defined leaseTime. Waits if necessary until lock became available. Lock will be released automatically after defined leaseTime interval.
        Parameters:
        leaseTime - the maximum time to hold the lock after it's acquisition, if it hasn't already been released by invoking unlock. If leaseTime is -1, hold the lock until explicitly unlocked.
        unit - the time unit
      • forceUnlock

        boolean forceUnlock()
        Unlocks the lock independently of its state
        Returns:
        true if lock existed and now unlocked otherwise false
      • isLocked

        boolean isLocked()
        Checks if the lock locked by any thread
        Returns:
        true if locked otherwise false
      • isHeldByThread

        boolean isHeldByThread​(long threadId)
        Checks if the lock is held by thread with defined threadId
        Parameters:
        threadId - Thread ID of locking thread
        Returns:
        true if held by thread with given id otherwise false
      • isHeldByCurrentThread

        boolean isHeldByCurrentThread()
        Checks if this lock is held by the current thread
        Returns:
        true if held by current thread otherwise false
      • getHoldCount

        int getHoldCount()
        Number of holds on this lock by the current thread
        Returns:
        holds or 0 if this lock is not held by current thread
      • remainTimeToLive

        long remainTimeToLive()
        Remaining time to live of the lock
        Returns:
        time in milliseconds -2 if the lock does not exist. -1 if the lock exists but has no associated expire.