[freenet-cvs] r17973 - trunk/freenet/src/freenet/support

nextgens at freenetproject.org nextgens at freenetproject.org
Sat Feb 16 02:46:05 UTC 2008


Author: nextgens
Date: 2008-02-16 02:46:05 +0000 (Sat, 16 Feb 2008)
New Revision: 17973

Modified:
   trunk/freenet/src/freenet/support/PooledExecutor.java
Log:
Fix the ArrayOutOfBound:

Two problems here:
- Java priorities start at 1, array indexes at 0 => decrement prio
- They are 10 levels of priority not 9

Modified: trunk/freenet/src/freenet/support/PooledExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/PooledExecutor.java	2008-02-16 02:11:34 UTC (rev 17972)
+++ trunk/freenet/src/freenet/support/PooledExecutor.java	2008-02-16 02:46:05 UTC (rev 17973)
@@ -14,7 +14,7 @@
  */
 public class PooledExecutor implements Executor {
 
-	private final ArrayList[] runningThreads /* <MyThread> */ = new ArrayList[NativeThread.JAVA_PRIO_RANGE];
+	private final ArrayList[] runningThreads /* <MyThread> */ = new ArrayList[NativeThread.JAVA_PRIO_RANGE + 1];
 	private final ArrayList[] waitingThreads /* <MyThread> */ = new ArrayList[runningThreads.length];
 	long[] threadCounter = new long[runningThreads.length];
 	private long jobCount;
@@ -60,8 +60,8 @@
 			boolean miss = false;
 			synchronized(this) {
 				jobCount++;
-				if(!waitingThreads[prio].isEmpty()) {
-					t = (MyThread) waitingThreads[prio].remove(waitingThreads[prio].size()-1);
+				if(!waitingThreads[prio-1].isEmpty()) {
+					t = (MyThread) waitingThreads[prio-1].remove(waitingThreads[prio-1].size()-1);
 				} else {
 					// Must create new thread
 					if((!fromTicker) && NativeThread.usingNativeCode() && prio < Thread.currentThread().getPriority()) {
@@ -70,8 +70,8 @@
 						return;
 					}
 					// Will be coalesced by thread count listings if we use "@" or "for"
-					t = new MyThread("Pooled thread awaiting work @"+(threadCounter[prio]), threadCounter[prio], prio, !fromTicker);
-					threadCounter[prio]++;
+					t = new MyThread("Pooled thread awaiting work @"+(threadCounter[prio-1]), threadCounter[prio-1], prio, !fromTicker);
+					threadCounter[prio-1]++;
 					t.setDaemon(true);
 					mustStart = true;
 					miss = true;
@@ -91,7 +91,7 @@
 			if(mustStart) {
 				t.start();
 				synchronized(this) {
-					runningThreads[prio].add(t);
+					runningThreads[prio-1].add(t);
 					if(miss)
 						jobMisses++;
 					if(logMINOR)
@@ -135,7 +135,7 @@
 				
 				if(job == null) {
 					synchronized(PooledExecutor.this) {
-						waitingThreads[nativePriority].add(this);
+						waitingThreads[nativePriority-1].add(this);
 					}
 					synchronized(this) {
 						if(nextJob == null) {
@@ -154,9 +154,9 @@
 						}
 					}
 					synchronized(PooledExecutor.this) {
-						waitingThreads[nativePriority].remove(this);
+						waitingThreads[nativePriority-1].remove(this);
 						if(!alive) {
-							runningThreads[nativePriority].remove(this);
+							runningThreads[nativePriority-1].remove(this);
 							if(logMINOR)
 								Logger.minor(this, "Exiting having executed "+ranJobs+" jobs : "+this);
 							return;




More information about the cvs mailing list