Browse Source

finer grained synchronization of current Thread task handling, only lock the threads table but do so consistently

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@669421 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
ea41c72f7a
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

@@ -176,10 +176,11 @@ public class Project implements ResourceFactory {
private ClassLoader coreLoader = null; private ClassLoader coreLoader = null;


/** Records the latest task to be executed on a thread. */ /** Records the latest task to be executed on a thread. */
private Map/*<Thread,Task>*/ threadTasks = Collections.synchronizedMap(new WeakHashMap());
private final Map/*<Thread,Task>*/ threadTasks =
Collections.synchronizedMap(new WeakHashMap());


/** Records the latest task to be executed on a thread group. */ /** Records the latest task to be executed on a thread group. */
private Map/*<ThreadGroup,Task>*/ threadGroupTasks
private final Map/*<ThreadGroup,Task>*/ threadGroupTasks
= Collections.synchronizedMap(new WeakHashMap()); = Collections.synchronizedMap(new WeakHashMap());


/** /**
@@ -2271,13 +2272,15 @@ public class Project implements ResourceFactory {
* @param task the task to be registered. * @param task the task to be registered.
* @since Ant 1.5 * @since Ant 1.5
*/ */
public synchronized void registerThreadTask(Thread thread, Task task) {
if (task != null) {
threadTasks.put(thread, task);
threadGroupTasks.put(thread.getThreadGroup(), task);
} else {
threadTasks.remove(thread);
threadGroupTasks.remove(thread.getThreadGroup());
public void registerThreadTask(Thread thread, Task task) {
synchronized(threadTasks) {
if (task != null) {
threadTasks.put(thread, task);
threadGroupTasks.put(thread.getThreadGroup(), task);
} else {
threadTasks.remove(thread);
threadGroupTasks.remove(thread.getThreadGroup());
}
} }
} }


@@ -2289,15 +2292,17 @@ public class Project implements ResourceFactory {
* null if no task is registered. * null if no task is registered.
*/ */
public Task getThreadTask(Thread thread) { public Task getThreadTask(Thread thread) {
Task task = (Task) threadTasks.get(thread);
if (task == null) {
ThreadGroup group = thread.getThreadGroup();
while (task == null && group != null) {
task = (Task) threadGroupTasks.get(group);
group = group.getParent();
synchronized(threadTasks) {
Task task = (Task) threadTasks.get(thread);
if (task == null) {
ThreadGroup group = thread.getThreadGroup();
while (task == null && group != null) {
task = (Task) threadGroupTasks.get(group);
group = group.getParent();
}
} }
return task;
} }
return task;
} }






Loading…
Cancel
Save