Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>java.util.Observable</code> makes many claims on what implementers are expected to do. However as an interface, none of this is enforced.</p> <p>The contract for <code>notifyObservers(Object o)</code> is:</p> <blockquote> <p>If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed. Each observer has its update method called with two arguments: this observable object and the arg argument.</p> </blockquote> <p>There is not an expectation of this method being synchronized. This means that if you are calling <code>notifyObservers(Object o)</code> in different threads it should not be expected to be synchronized.</p> <p>More important to your question, there is also not a corresponding expectation of <code>java.util.Observer.update(Observable a, Object arg)</code> finishing in a single thread. This means that you might call <code>notifyObservers(Object o)</code> all you like in a single thread, but <code>Observer.update(Observable a, Object arg)</code> might be spawning threads. If that is the case you cannot guarantee when the work it started will finish.</p> <p>If you are writing both the <code>Observers</code> and the <code>Observables</code> and you are not spawning threads, you can be sure that each call to <code>notifyObservers(Object o)</code> will finish only after the last call to <code>update(Observable o, Object arg)</code> finishes. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload