Package org.jppf.utils.concurrent
Class MutableReference<E>
java.lang.Object
org.jppf.utils.concurrent.MutableReference<E>
- Type Parameters:
E- The type of reference to handle.
Holds a mutable object reference witho no locking or synchronization mechanism.
This can be used in anonymous classes for mutating values without the cost of synchronization such as implemented in
AtomicReference.
For thread-safe access, instances of this class must be synchronized externally or by using the
{code getSynchronized(Object)} and setSynchronized(E, Object) methods.
- Since:
- 5.0
- Author:
- Laurent Cohen
-
Constructor Summary
ConstructorsConstructorDescriptionInitiaize this reference with the referend set to null.MutableReference(E referend) Initiaize this reference with the specified referend. -
Method Summary
Modifier and TypeMethodDescriptionget()Get the object held by this reference.getSynchronized(Object monitor) Get the referend within a block synchronized on the specified monitor.Set the object held by this reference.setSynchronized(E referend, Object monitor) Set the referend within a block synchronized on the specified monitor.
-
Constructor Details
-
MutableReference
public MutableReference()Initiaize this reference with the referend set to null. -
MutableReference
Initiaize this reference with the specified referend.- Parameters:
referend- the object held by this reference.
-
-
Method Details
-
get
Get the object held by this reference.- Returns:
- an object of the reference type.
-
set
Set the object held by this reference.- Parameters:
referend- an object of the reference type.- Returns:
- the new referend.
-
getSynchronized
Get the referend within a block synchronized on the specified monitor.- Parameters:
monitor- an object on which to synchronize.- Returns:
- an object of the reference type.
- Throws:
IllegalArgumentException- if the monitor is null.
-
setSynchronized
Set the referend within a block synchronized on the specified monitor.- Parameters:
referend- the value to set for this reference.monitor- an object on which to synchronize.- Returns:
- the new referend.
- Throws:
IllegalArgumentException- if the monitor is null.
-