Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 14,424
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Wait NotifyAll

Quote from the previous forum:


Posts: 36
From: New York
Registered: Nov, 2007

Wait NotifyAll
Posted: Jul 18, 2008 4:13 PM

Does any of you know how to implement an wait() to listen more than one type of events/signals and has timeout, which is simliar to WaitForMultiObjects in windows? or an alternative to achieve the goal?

Many thanks!

Can you provide some examples of what types of events you are listening for?  Are they events from a listener or are they sent between 2 of your own applicaitons?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
Posts: 6
Registered: ‎07-18-2008
My Device: Not Specified

Re: Wait NotifyAll

Hello Mark,


      Thanks! The events in my application come from the different threads in the same application, for example, main thread has an infinit loop acting like a daemon. In this loop, a wait function should be called while there are no events from the child threads, the wait function must be able to listen to multi-event so that main thread can act accordingly, for example, when the child thread  received a command 1 via HTTP XML from a remote server and then it issued an event to main thread to call function 1, whereas if the child thread received a command 2, main thread will call function 2 and so on. I want to how to implement a wait function for the purpose, or any alternative.



Many thanks!



Please use plain text.
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Wait NotifyAll

[ Edited ]
You could have a state bit that gets set before notifying the main thread. Then check the state to see which function to call.
Message Edited by mreed on 07-21-2008 11:30 AM
Please use plain text.
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Wait NotifyAll

  It sounds like you maybe have your work queue fleshed out already?


  If I understand you correctly, you want any number of threads to be able to send an event message to your work queue and have the work queue execute some code based on the message?  If that's the case, then your work queue is just implementing a dispatch table which is triggered on the incoming event.  The way I'd implement a dispatch table is, of course, in XML.


  Create a class to handle dispatch operations, say, DispatchTable.  When DispatchTable starts it would read an XML config file which would provide the mappings from event -> action and builds a Hashtable.  Something like:



  <mapping event="8" target="com.foo.bar.actions.Hasselbeck"/> 

  <mapping event="51" target="com.foo.bar.actions.Tatupu" />



 Each of your actions implements an interface, such as IDispatchAction, which contains a single method "execute()".  When your work queue receives an event it would delegate to the DispatchTable which would look up the event and invoke the action (which has been instantiated at some point by now).


  DispatchTable.dispatch(int event) {

    IDispatchAction action = getActionFromMyHashtable(event);




  Does any of this make sense?  It's kind of a tall design order.  :smileyhappy: 

Please use plain text.