ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r669421 - /ant/core/trunk/src/main/org/apache/tools/ant/Project.java
Date Thu, 19 Jun 2008 08:15:14 GMT
Author: bodewig
Date: Thu Jun 19 01:15:14 2008
New Revision: 669421

URL: http://svn.apache.org/viewvc?rev=669421&view=rev
Log:
finer grained synchronization of current Thread task handling, only lock the threads table
but do so consistently

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/Project.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?rev=669421&r1=669420&r2=669421&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Project.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Project.java Thu Jun 19 01:15:14 2008
@@ -176,10 +176,11 @@
     private ClassLoader coreLoader = null;
 
     /** 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. */
-    private Map/*<ThreadGroup,Task>*/ threadGroupTasks
+    private final Map/*<ThreadGroup,Task>*/ threadGroupTasks
         = Collections.synchronizedMap(new WeakHashMap());
 
     /**
@@ -2271,13 +2272,15 @@
      * @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 @@
      *         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;
     }
 
 



Mime
View raw message