Interface RLock

    • Method Detail

      • lockInterruptibly

        void lockInterruptibly​(long leaseTime,
                               TimeUnit unit)
                        throws InterruptedException
        Acquires the lock.

        If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. If the lock is acquired, it is held until unlock is invoked, or until leaseTime have passed since the lock was granted - whichever comes first.

        Parameters:
        leaseTime - the maximum time to hold the lock after granting it, before automatically releasing it if it hasn't already been released by invoking unlock. If leaseTime is -1, hold the lock until explicitly unlocked.
        unit - the time unit of the leaseTime argument
        Throws:
        InterruptedException - - if the thread is interrupted before or during this method.
      • tryLock

        boolean tryLock​(long waitTime,
                        long leaseTime,
                        TimeUnit unit)
                 throws InterruptedException
        Returns true as soon as the lock is acquired. If the lock is currently held by another thread in this or any other process in the distributed system this method keeps trying to acquire the lock for up to waitTime before giving up and returning false. If the lock is acquired, it is held until unlock is invoked, or until leaseTime have passed since the lock was granted - whichever comes first.
        Parameters:
        waitTime - the maximum time to aquire the lock
        leaseTime - lease time
        unit - time unit
        Returns:
        true if lock has been successfully acquired
        Throws:
        InterruptedException - - if the thread is interrupted before or during this method.
      • lock

        void lock​(long leaseTime,
                  TimeUnit unit)
        Acquires the lock.

        If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. If the lock is acquired, it is held until unlock is invoked, or until leaseTime milliseconds have passed since the lock was granted - whichever comes first.

        Parameters:
        leaseTime - the maximum time to hold the lock after granting it, before automatically releasing it if it hasn't already been released by invoking unlock. If leaseTime is -1, hold the lock until explicitly unlocked.
        unit - the time unit of the leaseTime argument
      • forceUnlock

        boolean forceUnlock()
        Unlocks lock independently of state
        Returns:
        true if unlocked otherwise false
      • isLocked

        boolean isLocked()
        Checks if this lock locked by any thread
        Returns:
        true if locked 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