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

nextgens at freenetproject.org nextgens at freenetproject.org
Sat Feb 16 02:11:34 UTC 2008


Author: nextgens
Date: 2008-02-16 02:11:34 +0000 (Sat, 16 Feb 2008)
New Revision: 17972

Modified:
   trunk/freenet/src/freenet/support/PooledExecutor.java
Log:
revert r17970 which was silly

Modified: trunk/freenet/src/freenet/support/PooledExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/PooledExecutor.java	2008-02-16 02:06:52 UTC (rev 17971)
+++ trunk/freenet/src/freenet/support/PooledExecutor.java	2008-02-16 02:11:34 UTC (rev 17972)
@@ -60,23 +60,21 @@
 			boolean miss = false;
 			synchronized(this) {
 				jobCount++;
-				synchronized(waitingThreads) {
-					if(!waitingThreads[prio].isEmpty())
-						t = (MyThread) waitingThreads[prio].remove(waitingThreads[prio].size() - 1);
-					else {
-						// Must create new thread
-						if((!fromTicker) && NativeThread.usingNativeCode() && prio < Thread.currentThread().getPriority()) {
-							// Run on ticker
-							ticker.queueTimedJob(job, 0, true);
-							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.setDaemon(true);
-						mustStart = true;
-						miss = true;
+				if(!waitingThreads[prio].isEmpty()) {
+					t = (MyThread) waitingThreads[prio].remove(waitingThreads[prio].size()-1);
+				} else {
+					// Must create new thread
+					if((!fromTicker) && NativeThread.usingNativeCode() && prio < Thread.currentThread().getPriority()) {
+						// Run on ticker
+						ticker.queueTimedJob(job, 0, true);
+						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.setDaemon(true);
+					mustStart = true;
+					miss = true;
 				}
 			}
 			synchronized(t) {
@@ -104,13 +102,11 @@
 		}
 	}
 
-	public int[] waitingThreads() {
-		synchronized(waitingThreads) {
-			int[] result = new int[waitingThreads.length];
-			for(int i = 0; i < result.length; i++)
-				result[i] = waitingThreads[i].size();
-			return result;
-		}
+	public synchronized int[] waitingThreads() {
+		int[] result = new int[waitingThreads.length];
+		for(int i=0; i<result.length; i++)
+			result[i] = waitingThreads[i].size();
+		return result;
 	}
 	
 	class MyThread extends NativeThread {
@@ -138,7 +134,7 @@
 				}
 				
 				if(job == null) {
-					synchronized(waitingThreads) {
+					synchronized(PooledExecutor.this) {
 						waitingThreads[nativePriority].add(this);
 					}
 					synchronized(this) {
@@ -157,7 +153,7 @@
 							// execute() won't give us another job if alive = false
 						}
 					}
-					synchronized(waitingThreads) {
+					synchronized(PooledExecutor.this) {
 						waitingThreads[nativePriority].remove(this);
 						if(!alive) {
 							runningThreads[nativePriority].remove(this);




More information about the cvs mailing list