Class MutableReference<E>

java.lang.Object
org.jppf.utils.concurrent.MutableReference<E>
Type Parameters:
E - The type of reference to handle.

public class MutableReference<E> extends Object
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 Details

    • MutableReference

      public MutableReference()
      Initiaize this reference with the referend set to null.
    • MutableReference

      public MutableReference(E referend)
      Initiaize this reference with the specified referend.
      Parameters:
      referend - the object held by this reference.
  • Method Details

    • get

      public E get()
      Get the object held by this reference.
      Returns:
      an object of the reference type.
    • set

      public E set(E referend)
      Set the object held by this reference.
      Parameters:
      referend - an object of the reference type.
      Returns:
      the new referend.
    • getSynchronized

      public E getSynchronized(Object monitor) throws IllegalArgumentException
      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

      public E setSynchronized(E referend, Object monitor) throws IllegalArgumentException
      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.