final class UniqueLockMonitor extends AutoCloseable
A stateful implementation of an auto-closable lock/monitor for the specified lock with an ability to unlock it preliminarily. The class philosophy and namings are borrowed from C++ std::unique_lock<>.
Usage example:
import scala.util.Using import java.util.concurrent.locks.ReentrantLock class Test { private val statusLock = new ReentrantLock() def tryWithResourceExample() = { Using( UniqueLockMonitor.lockAndMonitor( statusLock ) ) { monitor => // do something inside a lock } } def preliminaryUnlockExample() = { Using( UniqueLockMonitor.lockAndMonitor( statusLock ) ) { monitor => // do something inside a lock monitor.unlock() // do something else outside locking and UniqueLockMonitor.close() now does nothing } } }
- Note
this class isn't reentrant and isn't supposed to be shared across threads or used as a field. This class should be used as a stack/method local variable with try-with-resources.
- Alphabetic
- By Inheritance
- UniqueLockMonitor
- AutoCloseable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
close(): Unit
Auto close (unlock) if it hasn't been released or unlocked already.
Auto close (unlock) if it hasn't been released or unlocked already.
- Definition Classes
- UniqueLockMonitor → AutoCloseable
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
lock(): UniqueLockMonitor
Lock manually.
Lock manually. Consequent multiple locks aren't allowed to avoid mistakes and sharing monitor instances.
- returns
the same instance
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
release(): Lock
Release/take a lock from monitor, so it wouldn't be unlocked automatically in close.
Release/take a lock from monitor, so it wouldn't be unlocked automatically in close. You can't use lock/unlock after releasing a monitor.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
unlock(): UniqueLockMonitor
Unlock manually.
Unlock manually. Consequent multiple unlocks aren't allowed to avoid mistakes and sharing monitor instances.
- returns
the same instance
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()