• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Listener Mechanism

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to understand Listener mechanism in Java.
My query is regarding the notification, if there are 50 listener then will each notification be sent only and only if first one is complete
for eg
we call receiveBootEvent () on one listener and other listener will be only called when it returns from earlier call.
((BootListener) lCopy.elementAt( lIndex )).receiveBootEvent( aEventType );
-----------code -----------
public interface BootListener {

/** Receives a boot event.
* @param aEventType the type of the event.
*/
public void receiveBootEvent( int aEventType );
}
**********************************************
public void notifyListener( int aEventType ) {
if( aEventType == END_OF_BOOT ) mIsBootDone = true;
// Checks the number of listeners
if( mListener.size() == 0 ) return;
// Makes a local copy
Vector lCopy;
synchronized( this ) {
lCopy = (Vector) mListener.clone();
}
// Notifies all the listeners
for( int lIndex = 0 ; lIndex < lCopy.size() ; lIndex++ ) {
try {
((BootListener) lCopy.elementAt( lIndex )).receiveBootEvent( aEventType );
}
catch( Exception lException ) {
}
}

}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

That depends on the implementation. In your example, all listeners are notified sequentially, so each call depends on the previous receiveBootEvent emthod having returned. But in general, you can not make that assumption - listeners may be notified in parallel (using multiple threads), and in an order that is different each time a notification is sent out.
 
reply
    Bookmark Topic Watch Topic
  • New Topic