From ea41c72f7adfce4ad48caded93962140650f2746 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 19 Jun 2008 08:15:14 +0000 Subject: [PATCH] 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 --- src/main/org/apache/tools/ant/Project.java | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index c45d29e92..d913a8dc7 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -176,10 +176,11 @@ public class Project implements ResourceFactory { private ClassLoader coreLoader = null; /** Records the latest task to be executed on a thread. */ - private Map/**/ threadTasks = Collections.synchronizedMap(new WeakHashMap()); + private final Map/**/ threadTasks = + Collections.synchronizedMap(new WeakHashMap()); /** Records the latest task to be executed on a thread group. */ - private Map/**/ threadGroupTasks + private final Map/**/ threadGroupTasks = Collections.synchronizedMap(new WeakHashMap()); /** @@ -2271,13 +2272,15 @@ public class Project implements ResourceFactory { * @param task the task to be registered. * @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. */ 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; }