Forums Register Login

Listener Mechanism

+Pie Number of slices to send: Send
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 ) {
}
}

}
+Pie Number of slices to send: Send
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.
Uh oh, we're definitely being carded. Here, show him this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 771 times.
Similar Threads
Extended Listener Pattern
How to write my own Event ( & Listener for it)??
It's about JavaBeans
Multiple users of a HashMap / Iterator - Handling Synchronization
How to create user defined and customized call back method in core java?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:47:27.