Package com.iizix
Class AutoLock
java.lang.Object
com.iizix.AutoLock
- All Implemented Interfaces:
Serializable
,AutoCloseable
Reentrant lock that can be used in a try-with-resources statement.
Typical usage:
try (AutoLock lock=this.lock.lock()) { // Something }
- See Also:
Constructor Details
AutoLock
public AutoLock()Constructs the reentrant lock, unlocked.
Method Details
lock
Acquires the lock.
- Returns:
this
AutoLock for unlocking.
isHeldByCurrentThread
public boolean isHeldByCurrentThread()Queries if this lock is held by the current thread.- Returns:
- Whether this lock is held by the current thread.
- See Also:
close
public void close()(Auto) closes the instance by unlocking the reentrant lock.- Specified by:
close
in interfaceAutoCloseable