In the Observer Design Pattern, the subject notifies all observers by calling the update() operation of each observer. One way of doing this is
void notify() {
for (observer: observers) {
observer.update(this);
}
}
But the problem here is each observer is updated in a sequence and update operation for an observer might not be called till all the observers before it is updated. If there is an observer that has an infinite loop for update then all the observer after it will never be notified.
Question:
- Is there a way to get around this problem?
- If so what would be a good example?
Classic design patterns do not involve parallelism and threading. You’d have to spawn N threads for the N observers. Be careful though since their interaction to this will have to be done in a thread safe manner.