Author: j16sdiz
Date: 2009-04-03 08:58:50 +0000 (Fri, 03 Apr 2009)
New Revision: 26415

Modified:
   trunk/freenet/src/freenet/support/SerialExecutor.java
Log:
Fix SerialExecutor thread count, rename variables

Modified: trunk/freenet/src/freenet/support/SerialExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/SerialExecutor.java       2009-04-03 
08:58:28 UTC (rev 26414)
+++ trunk/freenet/src/freenet/support/SerialExecutor.java       2009-04-03 
08:58:50 UTC (rev 26415)
@@ -9,11 +9,11 @@
 
        private final LinkedList<Runnable> jobs;
        private final int priority;
-       private boolean waiting;
+       private boolean threadWaiting;
        
        private String name;
        private Executor realExecutor;
-       private boolean running;
+       private boolean threadStarted;
        
        private static final int NEWJOB_TIMEOUT = 5*60*1000;
        
@@ -28,16 +28,16 @@
                                Runnable job;
                                synchronized(jobs) {
                                        if(jobs.isEmpty()) {
-                                               waiting = true;
+                                               threadWaiting = true;
                                                try {
                                                        //NB: notify only on 
adding work or this quits early.
                                                        
jobs.wait(NEWJOB_TIMEOUT);
                                                } catch (InterruptedException 
e) {
                                                        // Ignore
                                                }
-                                               waiting=false;
+                                               threadWaiting=false;
                                                if (jobs.isEmpty()) {
-                                                       running=false;
+                                                       threadStarted=false;
                                                        return;
                                                }
                                        }
@@ -69,7 +69,7 @@
        }
        
        private void reallyStart(boolean logMINOR) {
-               running=true;
+               threadStarted=true;
                if(logMINOR) Logger.minor(this, "Starting thread... "+name+" : 
"+runner);
                realExecutor.execute(runner, name);
        }
@@ -77,10 +77,10 @@
        public void execute(Runnable job, String jobName) {
                boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                synchronized(jobs) {
-                       if(logMINOR) Logger.minor(this, "Running "+jobName+" : 
"+job+" running="+running+" waiting="+waiting);
+                       if(logMINOR) Logger.minor(this, "Running "+jobName+" : 
"+job+" running="+threadStarted+" waiting="+threadWaiting);
                        jobs.addLast(job);
                        jobs.notifyAll();
-                       if (!running && realExecutor!=null) {
+                       if (!threadStarted && realExecutor!=null) {
                                reallyStart(logMINOR);
                        }
                }
@@ -92,7 +92,7 @@
 
        public int[] runningThreads() {
                int[] retval = new int[NativeThread.JAVA_PRIORITY_RANGE+1];
-               if (running)
+               if (threadStarted && !threadWaiting)
                        retval[priority] = 1;
                return retval;
        }
@@ -100,7 +100,7 @@
        public int[] waitingThreads() {
                int[] retval = new int[NativeThread.JAVA_PRIORITY_RANGE+1];
                synchronized(jobs) {
-                       if(waiting)
+                       if(threadStarted && threadWaiting)
                                retval[priority] = 1;
                }
                return retval;
@@ -108,7 +108,7 @@
 
        public int getWaitingThreadsCount() {
                synchronized(jobs) {
-                       return (waiting ? 1 : 0);
+                       return (threadStarted && threadWaiting) ? 1 : 0;
                }
        }
 }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to