Author: toad
Date: 2007-08-11 20:21:18 +0000 (Sat, 11 Aug 2007)
New Revision: 14635

Modified:
   trunk/freenet/src/freenet/support/PooledExecutor.java
Log:
Add to one end (when become idle) and take from the other (when need a thread).
Otherwise threads will never timeout.

Modified: trunk/freenet/src/freenet/support/PooledExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/PooledExecutor.java       2007-08-11 
20:10:12 UTC (rev 14634)
+++ trunk/freenet/src/freenet/support/PooledExecutor.java       2007-08-11 
20:21:18 UTC (rev 14635)
@@ -4,6 +4,7 @@
 package freenet.support;

 import java.util.ArrayList;
+import java.util.LinkedList;

 /**
  * Pooled Executor implementation. Create a thread when we need one, let them 
die
@@ -13,7 +14,7 @@
 public class PooledExecutor implements Executor {

        private final ArrayList runningThreads /* <MyThread> */ = new 
ArrayList();
-       private final ArrayList waitingThreads /* <MyThread> */ = new 
ArrayList();
+       private final LinkedList waitingThreads /* <MyThread> */ = new 
LinkedList();
        long threadCounter = 0;

        /** Maximum time a thread will wait for a job */
@@ -25,7 +26,7 @@
                        boolean mustStart = false;
                        synchronized(this) {
                                if(!waitingThreads.isEmpty()) {
-                                       t = (MyThread) 
waitingThreads.remove(waitingThreads.size()-1);
+                                       t = (MyThread) 
waitingThreads.removeLast();
                                } else {
                                        // Will be coalesced by thread count 
listings if we use "@" or "for"
                                        t = new MyThread("Pooled thread 
awaiting work @"+(threadCounter++));
@@ -80,7 +81,7 @@

                                if(job == null) {
                                        synchronized(PooledExecutor.this) {
-                                               waitingThreads.add(this);
+                                               waitingThreads.addFirst(this);
                                        }
                                        synchronized(this) {
                                                if(nextJob == null) {


Reply via email to