Author: toad
Date: 2009-03-13 21:08:22 +0000 (Fri, 13 Mar 2009)
New Revision: 26024

Modified:
   branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java
Log:
Prevent database threads (or runners for anything else using 
PrioritisedSerialExecutor) from multiplying!


Modified: 
branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java    
2009-03-13 21:07:32 UTC (rev 26023)
+++ branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java    
2009-03-13 21:08:22 UTC (rev 26024)
@@ -35,7 +35,16 @@
 
                public void run() {
                        long lastDumped = System.currentTimeMillis();
-                       current = Thread.currentThread();
+                       synchronized(jobs) {
+                               if(current != null) {
+                                       if(current.isAlive()) {
+                                               Logger.error(this, "Already 
running a thread for "+this+" !!", new Exception("error"));
+                                               return;
+                                       }
+                               }
+                               current = Thread.currentThread();
+                       }
+                       try {
                        while(true) {
                                boolean logMINOR = 
Logger.shouldLog(Logger.MINOR, this);
                                Runnable job = null;
@@ -94,6 +103,12 @@
                                        Logger.error(this, "While running 
"+job+" on "+this);
                                }
                        }
+                       } finally {
+                               synchronized(jobs) {
+                                       current = null;
+                                       running = false;
+                               }
+                       }
                }
 
                private Runnable checkQueue() {
@@ -152,9 +167,15 @@
        }
        
        private void reallyStart(boolean logMINOR) {
-               running=true;
-               if(logMINOR) Logger.minor(this, "Starting thread... "+name+" : 
"+runner);
-               realExecutor.execute(runner, name);
+               synchronized(jobs) {
+                       if(running) {
+                               Logger.error(this, "Not reallyStart()ing: 
ALREADY RUNNING", new Exception("error"));
+                               return;
+                       }
+                       running=true;
+                       if(logMINOR) Logger.minor(this, "Starting thread... 
"+name+" : "+runner, new Exception("debug"));
+                       realExecutor.execute(runner, name);
+               }
        }
        
        public void execute(Runnable job, String jobName) {

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

Reply via email to