• Post Reply Bookmark Topic Watch Topic
  • New Topic

Observer Pattern vs Object.notifyAll()

 
Richard Broersma
Ranch Hand
Posts: 63
Firefox Browser Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While study for the SCJP test, I finally reached the section on Threads.

I'm curious, is the purpose of the Observer Pattern similar to the purpose the Object.wait() - Object.notifyAll(). It seems that they are, but are there any subtle differences between them where one design per preferable to the other?
 
Rok Ć telcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Richard Broersma wrote:
I'm curious, is the purpose of the Observer Pattern similar to the purpose the Object.wait() - Object.notifyAll()

Not really.

Richard Broersma wrote:It seems that they are, but are there any subtle differences between them where one design per preferable to the other?

Object.notifyAll, notifies all threads that are waiting on this object's monitor (lock).
However, only the one which acquires the lock will be able to "proceed".

Observer (publisher/subscriber) is a bit different.
After the publisher notifies all registered subscribers, it is up to them if they will process the given information or not.
The point is that they all have the possibility to process it.

I'd have to say that you can't compare those two ... although they look the same, both are used and designed for different situations.

Well, at least in my opinion ... ;)


Regards,
Rok
 
Richard Broersma
Ranch Hand
Posts: 63
Firefox Browser Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I'll give some thought to what you've written.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!