Package com.android.utils.concurrency
Interface ReadWriteThreadLock.Lock
-
- Enclosing class:
- ReadWriteThreadLock
public static interface ReadWriteThreadLock.Lock
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidlock()Acquires the lock, blocking to wait until the lock can be acquired.booleantryLock(long timeout, java.util.concurrent.TimeUnit timeUnit)Tries acquiring the lock, blocking to wait until the lock can be acquired or the specified time has passed, then returnstruein the first case andfalsein the second case.voidunlock()Releases the lock.
-
-
-
Method Detail
-
lock
void lock()
Acquires the lock, blocking to wait until the lock can be acquired.If the thread executing this method is interrupted, this method will throw a runtime exception.
-
tryLock
boolean tryLock(long timeout, @NonNull java.util.concurrent.TimeUnit timeUnit)Tries acquiring the lock, blocking to wait until the lock can be acquired or the specified time has passed, then returnstruein the first case andfalsein the second case.If the thread executing this method is interrupted, this method will throw a runtime exception.
This method will try acquiring the lock first before checking for timeout. A non-positive timeout means the method will return immediately after the first try. This behavior is similar to a
ReentrantReadWriteLock.- Parameters:
timeout- the maximum time to wait for the locktimeUnit- the unit of the timeout- Returns:
trueif the lock was acquired
-
unlock
void unlock()
Releases the lock. This method does not block.
-
-