What methods must a class implementing the java.util.concurrent.locks.Lock interface implement? Describe some of the expected characteristics of each of the methods of this interface?
Lock interface provide these unimplemented methods -
1- void lock() – acquire the lock if it's available; if the lock isn't available a thread gets blocked until the lock is released.
2- void lockInterruptibly() – this is similar to the lock(), but it allows the blocked thread to be interrupted and resume the execution through a thrown java.lang.InterruptedException
3- boolean tryLock() – this is a non-blocking version of lock() method; it attempts to acquire the lock immediately, return true if locking succeeds
4- boolean tryLock(long timeout, TimeUnit timeUnit) – this is similar to tryLock(), except it waits up the given timeout before giving up trying to acquire the Lock
5- void unlock() – unlocks the Lock instance
Get Answers For Free
Most questions answered within 1 hours.