Class SynchronizedObservable<T>

  • Type Parameters:
    T - the type of the values to observe
    All Implemented Interfaces:
    Observable<T>

    public class SynchronizedObservable<T>
    extends SimpleObservable<T>
    A thread-safe implementation of Observable. This should only be used in situations where observers are very likely to run in multiple threads. Otherwise, SimpleObservable should be used to avoid the penalties of synchronized and lock contention.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addObserver​(Observer<? super T> observer)
      Add an observer to this observable.
      T get()
      Gets the current value of this observable.
      void removeObserver​(Observer<? super T> observer)
      Removes an observer from this observable.
      void set​(T value)
      Sets the value of this observable.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addObserver

        public void addObserver​(Observer<? super T> observer)
        Description copied from interface: Observable
        Add an observer to this observable. It will be notified of any future changes to the value of this observable. Listeners will be fired in the order in which they were added, and on the thread that updates the observed value. Because of this, listeners should take as little time as possible to run (unless submitting a long-running task to a worker thread).
        Specified by:
        addObserver in interface Observable<T>
        Overrides:
        addObserver in class SimpleObservable<T>
      • set

        public void set​(T value)
        Description copied from interface: Observable
        Sets the value of this observable. If it's not equal to the current value, all observers will be notified of the change.
        Specified by:
        set in interface Observable<T>
        Overrides:
        set in class SimpleObservable<T>