Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Observer pattern notifyAll () -- is it blocking?  RSS feed

 
Bob Pool
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a question regarding Observer and Observable objects in Java.
I have a scenario where a notification needs to be received and passed it along to the observers without blocking for the observers to complete.
The observers do quite a bit of work and can take a long time to return control. The expectation is that the response is returned back
immediately to the caller with 'Yes, I got your notification'.

I am working with EJBs and cannot spawn threads on my own.
I notice that notifyAll() in observable calls update() method of the observer and blocks.

How do I achieve non-blocking notification when I cannot spawn separate threads?

thanks for your help.

Regards,
Bob
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the only way to have the update() method immediately bounce back it to have the update logic run in a separate Thread.
 
Maruthi Janardhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you cant start threads and you have an EJB container, what is JMS for? Drop a JMS message in a queue and let an MDB process your notifications asynchronously. Your code returns to tell "Yes, I got your notification"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!