When I call:
setChanged();
notifyObservers();
on a java.until.Observable class, will all the listening Observer objects complete execution of their udpate() methods – assuming we are running in the same Thread – before the java.until.Observable class continues running?
This is important because I will be sending a few messages through the notifyObservers(Object o) method in quick concession, it is important that each Observer class has finished its method before the new one though.
I understand that the order of execution for each Observer class may vary when we call notifyObservers() – it is just important that the order of method execution for each individual instance is in order.
java.util.Observablemakes many claims on what implementers are expected to do. However as an interface, none of this is enforced.The contract for
notifyObservers(Object o)is:There is not an expectation of this method being synchronized. This means that if you are calling
notifyObservers(Object o)in different threads it should not be expected to be synchronized.More important to your question, there is also not a corresponding expectation of
java.util.Observer.update(Observable a, Object arg)finishing in a single thread. This means that you might callnotifyObservers(Object o)all you like in a single thread, butObserver.update(Observable a, Object arg)might be spawning threads. If that is the case you cannot guarantee when the work it started will finish.If you are writing both the
Observersand theObservablesand you are not spawning threads, you can be sure that each call tonotifyObservers(Object o)will finish only after the last call toupdate(Observable o, Object arg)finishes.