Java Locks
- lock() locks the Lock instance if possible. If the Lock
instance is already locked, the thread calling lock() is
blocked until the Lock is unlocked.
- lockInterruptibly() locks the Lock unless the thread
calling the method has been interrupted.
- tryLock() method attempts to lock the Lock instance
immediately. It returns true if the locking succeeds, false if Lock is
already locked. This method never blocks.
- tryLock(long timeout, TimeUnit timeUnit) works like the
tryLock() method, except it waits up the given timeout before giving up
trying to lock the Lock.
- unlock() unlocks the Lock instance. If the Lock is already unlocked, it throws an IllegalMonitorStateException.