Browse Source

Add a separate lock for the BuildListener collection

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@669426 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
a65cadb437
1 changed files with 21 additions and 16 deletions
  1. +21
    -16
      src/main/org/apache/tools/ant/Project.java

+ 21
- 16
src/main/org/apache/tools/ant/Project.java View File

@@ -166,6 +166,9 @@ public class Project implements ResourceFactory {
/** Project base directory. */
private File baseDir;

/** lock object used when adding/removing listeners */
private final Object listenersLock = new Object();

/** List of listeners to notify of build events. */
private Vector listeners = new Vector();

@@ -378,16 +381,17 @@ public class Project implements ResourceFactory {
* @param listener The listener to add to the list.
* Must not be <code>null</code>.
*/
public synchronized void addBuildListener(BuildListener listener) {
// If the listeners already has this listener, do nothing
if (listeners.contains(listener)) {
return;
public void addBuildListener(BuildListener listener) {
synchronized (listenersLock) {
// If the listeners already has this listener, do nothing
if (listeners.contains(listener)) {
return;
}
// copy on write semantics
Vector newListeners = getBuildListeners();
newListeners.addElement(listener);
listeners = newListeners;
}
// create a new Vector to avoid ConcurrentModificationExc when
// the listeners get added/removed while we are in fire
Vector newListeners = getBuildListeners();
newListeners.addElement(listener);
listeners = newListeners;
}

/**
@@ -397,12 +401,13 @@ public class Project implements ResourceFactory {
* @param listener The listener to remove from the list.
* Should not be <code>null</code>.
*/
public synchronized void removeBuildListener(BuildListener listener) {
// create a new Vector to avoid ConcurrentModificationExc when
// the listeners get added/removed while we are in fire
Vector newListeners = getBuildListeners();
newListeners.removeElement(listener);
listeners = newListeners;
public void removeBuildListener(BuildListener listener) {
synchronized (listenersLock) {
// copy on write semantics
Vector newListeners = getBuildListeners();
newListeners.removeElement(listener);
listeners = newListeners;
}
}

/**
@@ -2152,7 +2157,7 @@ public class Project implements ResourceFactory {
*
* @see http://marc.theaimsgroup.com/?t=110538624200006&r=1&w=2
*
* We now (Ant 1.7 and 1.6.3) simply swallow the message.
* We now (Ant 1.6.3 and later) simply swallow the message.
*/
return;
}


Loading…
Cancel
Save