• Post Reply Bookmark Topic Watch Topic
  • New Topic

Listener Mechanism  RSS feed

 
Ratika Chandra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 ) {
}
}

}
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!