r26750 - trunk/freenet/src/freenet/support

[email protected]
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: j16sdiz
Date: 2009-04-12 11:31:04 +0000 (Sun, 12 Apr 2009)
New Revision: 26750

Modified:
   trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java
Log:
Revert r26639 "Keep job counts"

Turns out this is not a good idea (for now).

Modified: trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java	2009-04-11 23:32:54 UTC (rev 26749)
+++ trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java	2009-04-12 11:31:04 UTC (rev 26750)
@@ -11,8 +11,6 @@
 public class PrioritizedSerialExecutor implements Executor {
 	
 	private final LinkedList<Runnable>[] jobs;
-	private final int[] jobCount;
-	
 	private final int priority;
 	private final int defaultPriority;
 	private boolean waiting;
@@ -119,11 +117,7 @@
 					if(!jobs[i].isEmpty()) {
 						if(Logger.shouldLog(Logger.MINOR, this))
 							Logger.minor(this, "Chosen job at priority "+i);
-						synchronized (jobs) {
-							Runnable r = jobs[i].removeFirst();
-							jobCount[i]--;
-							return r;
-						}
+						return (Runnable) jobs[i].removeFirst();
 					}
 				}
 			} else {
@@ -131,11 +125,7 @@
 					if(!jobs[i].isEmpty()) {
 						if(Logger.shouldLog(Logger.MINOR, this))
 							Logger.minor(this, "Chosen job at priority "+i);
-						synchronized (jobs) {
-							Runnable r = jobs[i].removeFirst();
-							jobCount[i]--;
-							return r;
-						}
+						return (Runnable) jobs[i].removeFirst();
 					}
 				}
 			}
@@ -155,7 +145,6 @@
 		jobs = new LinkedList[internalPriorityCount];
 		for(int i=0;i<jobs.length;i++)
 			jobs[i] = new LinkedList<Runnable>();
-		jobCount = new int[internalPriorityCount];
 		this.priority = priority;
 		this.defaultPriority = defaultPriority;
 		this.invertOrder = invertOrder;
@@ -202,7 +191,6 @@
 			if(logMINOR) 
 				Logger.minor(this, "Running "+jobName+" : "+job+" priority "+prio+" running="+running+" waiting="+waiting);
 			jobs[prio].addLast(job);
-			jobCount[prio]++;
 			jobs.notifyAll();
 			if(!running && realExecutor != null) {
 				reallyStart(logMINOR);
@@ -221,7 +209,6 @@
 				return;
 			}
 			jobs[prio].addLast(job);
-			jobCount[prio]++;
 			jobs.notifyAll();
 			if(!running && realExecutor != null) {
 				reallyStart(logMINOR);
@@ -258,16 +245,17 @@
 	}
 
 	public int[] queuedJobs() {
-		int[] retval;
+		int[] retval = new int[jobs.length];
 		synchronized(jobs) {
-			retval = jobCount.clone();
+			for(int i=0;i<retval.length;i++)
+				retval[i] = jobs[i].size();
 		}
 		return retval;
 	}
 
 	public int getQueueSize(int priority) {
 		synchronized(jobs) {
-			return jobCount[priority];
+			return jobs[priority].size();
 		}
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.