Alternative to observer pattern

Does anyone know an alternative to the Observer aka Listener template? What interests me is that it will work well in the asynchronous Environment. The problem I am facing is that I have an application that uses this (which is not so bad), but this becomes a bottleneck as the number of listeners increases; In combination with primitives for threading (mutexes, critical sections - of course, in my particular environment), the performance hit is very bad.

+7
source share
5 answers

What about Message Queue ?

+7
source

If there are too many observers, so the observed stream does not advance, then it would be wise to change the relationship. Instead of causing the observed stream to cause each observer, it might be better for the observers to wait for something like a condition variable or event associated with the observed stream. Then the observer code can be blocked, waiting for the condition variable to be signaled. The observed thread can then simply signal the condition variable, rather than ring the observer; observers can notice the signal and process the consequences in due time.

+3
source

Please take a look at this if you reduce your listeners in code - your main goal is Jeffrey Richter and his AsyncEnumerator . This method makes an asynchronous software process more like a synchronous one.

Using this technique, your only method can call Asynch and resto on a method that acts as an event handler, so all the call code and events to listen for events can be arranged as one function.

+1
source

Two alternatives from me: using an actor model (e.g. akka framework) or using an artist to limit parallelization. An artist is simply a thread pool that limits the number of threads and reuses ready-made threads.

0
source

It is difficult to say without a more specific description, but the intermediary pattern is connected and can be used when the number of communication objects begin to multiply. You could implement some policy to coordinate actions in a more structured way within these.

0
source

All Articles