[jboss-cvs] JBoss Messaging SVN: r4218 - trunk/src/main/org/jboss/messaging/util.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 16 09:21:11 EDT 2008


Author: jmesnil
Date: 2008-05-16 09:21:10 -0400 (Fri, 16 May 2008)
New Revision: 4218

Modified:
   trunk/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java
Log:
* replace LinkedList by a LinkedBlockingQueue

Modified: trunk/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java	2008-05-16 11:26:27 UTC (rev 4217)
+++ trunk/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java	2008-05-16 13:21:10 UTC (rev 4218)
@@ -8,9 +8,10 @@
 
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.Queue;
 import java.util.Set;
 import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingQueue;
 
 /**
  * This factory creates a hierarchy of Executor which shares the threads of the
@@ -39,17 +40,14 @@
 
    private final class ChildExecutor implements Executor, Runnable
    {
-      private final LinkedList<Runnable> tasks = new LinkedList<Runnable>();
-
+      private final Queue<Runnable> tasks = new LinkedBlockingQueue<Runnable>();
+      
       public void execute(Runnable command)
       {
-         synchronized (tasks)
+         tasks.offer(command);
+         if (tasks.size() == 1 && runningChildren.add(this))
          {
-            tasks.add(command);
-            if (tasks.size() == 1 && runningChildren.add(this))
-            {
-               parent.execute(this);
-            }
+            parent.execute(this);
          }
       }
 
@@ -57,15 +55,11 @@
       {
          for (;;)
          {
-            final Runnable task;
-            synchronized (tasks)
+            final Runnable task = tasks.poll();
+            if (task == null)
             {
-               task = tasks.poll();
-               if (task == null)
-               {
-                  runningChildren.remove(this);
-                  return;
-               }
+               runningChildren.remove(this);
+               return;
             }
             task.run();
          }




More information about the jboss-cvs-commits mailing list