Stefan Bodewig wrote:

On Fri, 15 Aug 2003, Nicola Ken Barozzi <[EMAIL PROTECTED]> wrote:



DirectoryScanner.scandir Does somebody know anybody working on Ant
logging system? Is Ant 1.6 better in this regard?



Ant's DirectoryScanner may have become a lot (and I mean a lot) faster in 1.6, depending on the patterns you use.



PS Removing synchronized() in this method gives even better
results



We allow listeners to be added and removed during event logging and we may be running several tasks in <parallel>, so I'm afraid that removing synchronized may be doing more harm than help.

For the same reason we clone the Vector of listeners before we start
to fire events. In the patched code, we'd at least have to copy the
array and iterate over that copy to avoid problems when a listener
removes itself in response to a logged message.



To solve this problem, you may consider the fact that listeners are more often fired than changed, and therefore use a different pattern, which does the cloning and synchronisation when the listener list has to be changed, and not when it has to be traversed.


private List listenerers;

public void fireEvent(Event ev) {
 Iterator iter = this.listeners.iterator();
 while(iter.hasNext()) {
   ((EventListener)iter.next()).fireEvent(ev);
 }
}

public void synchronized addListener(EventListener evl) {
 // Make a local copy on which we will act : it avoids
 // ConcurrentModificationException if someone is executing fireEvent()
 List newListeners = this.listeners.clone();
 newListeners.add(evl);
 // and replace the listener list
 this.listeners = newListeners;
}

Sylvain

--
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



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



Reply via email to