I would suggest copying the vector elements to an array before iterating
over them and notifying them of the event. The copy should be done in a
synchronized block but the event delivery should be done outside the sync
block. I know it's not the most efficient way to do it but it does give you
correct behaviour and performance is not really an issue here as these
events should not be fired often.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
> Sent: 10 December 2002 05:33
> To: Log4J Developers List
> Subject: synchronization problem with listeners in Hierarchy?
> 
> 
> So, this is some of the code that I added to Hierarchy:
> 
>   /**
>     Requests that a configuration changed event be sent to 
> any registered
>     {@link LoggerRepositoryEventListener}.
>     @since 1.3*/
>   public void fireConfigurationChangedEvent() {
>     if(repositoryEventListeners != null) {
>       int size = repositoryEventListeners.size();
>       LoggerRepositoryEventListener listener;
>       for(int i = 0; i < size; i++) {
>         listener = (LoggerRepositoryEventListener)
>           repositoryEventListeners.elementAt(i);
>         listener.configurationChangedEvent(this);
>       }
>     }
>   }
> 
> But there are also methods that allow one to remove a given 
> listener from the hierarchy.  So, there will be a problem 
> here if a listener is removed while in the for loop to 
> reportiting an event.
> 
> What would be the best way to deal with it?  Just add a catch 
> for the index out of bounds exception or to synchronize on 
> the listener vectors?
> 
> -Mark
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:log4j-dev-> [EMAIL PROTECTED]>
> For 
> additional commands, 
> e-mail: <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to