public LockResult lock ( final TaskLockType lockType , final Task task , final Interval interval , long timeoutMs ) throws InterruptedException { long nanos = TimeUnit . MILLISECONDS . toNanos ( timeoutMs ) ; giant . lockInterruptibly ( ) ; try { LockResult lockResult ; while ( ! ( lockResult = tryLock ( lockType , task , interval ) ) . isOk ( ) ) { if ( nanos <= 0 || lockResult . isRevoked ( ) ) { return lockResult ; } nanos = lockReleaseCondition . awaitNanos ( nanos ) ; } return lockResult ; } finally { giant . unlock ( ) ; } }
Acquires a lock on behalf of a task waiting up to the specified wait time if necessary .