Class SynchronizedRef
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
EDU.oswego.cs.dl.util.concurrent.SynchronizedRef
- All Implemented Interfaces:
Executor
- Direct Known Subclasses:
WaitableRef
A simple class maintaining a single reference variable that
is always accessed and updated under synchronization.
-
Field Summary
FieldsFields inherited from class SynchronizedVariable
lock_ -
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedRef(Object initialValue) Create a SynchronizedRef initially holding the given reference and using its own internal lock.SynchronizedRef(Object initialValue, Object lock) Make a new SynchronizedRef with the given initial value, and using the supplied lock. -
Method Summary
Modifier and TypeMethodDescriptionbooleanSet value to newValue only if it is currently assumedValue.final Objectget()Return the current valueSet to newValue.swap(SynchronizedRef other) Atomically swap values with another SynchronizedRef.Methods inherited from class SynchronizedVariable
execute, getLock
-
Field Details
-
value_
The maintained reference
-
-
Constructor Details
-
SynchronizedRef
Create a SynchronizedRef initially holding the given reference and using its own internal lock. -
SynchronizedRef
-
-
Method Details
-
get
Return the current value -
set
-
commit
-
swap
Atomically swap values with another SynchronizedRef. Uses identityHashCode to avoid deadlock when two SynchronizedRefs attempt to simultaneously swap with each other. (Note: Ordering via identyHashCode is not strictly guaranteed by the language specification to return unique, orderable values, but in practice JVMs rely on them being unique.)- Returns:
- the new value
-