Author: toad
Date: 2007-08-15 17:24:48 +0000 (Wed, 15 Aug 2007)
New Revision: 14707

Modified:
   trunk/freenet/src/freenet/node/NodeStarter.java
   trunk/freenet/src/freenet/support/PooledExecutor.java
Log:
Logging for PooledExecutor.
It appears that PooledExecutor very efficiently prevents new threads from being 
created.

Modified: trunk/freenet/src/freenet/node/NodeStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStarter.java     2007-08-15 17:23:30 UTC 
(rev 14706)
+++ trunk/freenet/src/freenet/node/NodeStarter.java     2007-08-15 17:24:48 UTC 
(rev 14707)
@@ -89,8 +89,6 @@
        java.security.Security.setProperty("networkaddress.cache.ttl" , "0");
        java.security.Security.setProperty("networkaddress.cache.negative.ttl" 
, "0");

-       Executor executor = new PooledExecutor();
-       
        try{
                cfg = 
FreenetFilePersistentConfig.constructFreenetFilePersistentConfig(configFilename);
 
        }catch(IOException e){
@@ -102,6 +100,8 @@
        // First, set up logging. It is global, and may be shared between 
several nodes.
        SubConfig loggingConfig = new SubConfig("logger", cfg);

+       PooledExecutor executor = new PooledExecutor();
+       
        try {
                logConfigHandler = new LoggingConfigHandler(loggingConfig, 
executor);
        } catch (InvalidConfigValueException e) {
@@ -110,6 +110,8 @@
                return new Integer(-2);
        }

+       executor.start();
+       
        getExtBuild();

        // Setup RNG

Modified: trunk/freenet/src/freenet/support/PooledExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/PooledExecutor.java       2007-08-15 
17:23:30 UTC (rev 14706)
+++ trunk/freenet/src/freenet/support/PooledExecutor.java       2007-08-15 
17:24:48 UTC (rev 14707)
@@ -15,15 +15,24 @@
        private final ArrayList runningThreads /* <MyThread> */ = new 
ArrayList();
        private final ArrayList waitingThreads /* <MyThread> */ = new 
ArrayList();
        long threadCounter = 0;
+       private long jobCount;
+       private long jobMisses;
+       private static boolean logMINOR;

        /** Maximum time a thread will wait for a job */
        static final int TIMEOUT = 5*60*1000;

+       public void start() {
+               logMINOR = Logger.shouldLog(Logger.MINOR, this);
+       }
+       
        public void execute(Runnable job, String jobName) {
                while(true) {
                        MyThread t;
                        boolean mustStart = false;
+                       boolean miss = false;
                        synchronized(this) {
+                               jobCount++;
                                if(!waitingThreads.isEmpty()) {
                                        t = (MyThread) 
waitingThreads.remove(waitingThreads.size()-1);
                                } else {
@@ -31,6 +40,7 @@
                                        t = new MyThread("Pooled thread 
awaiting work @"+(threadCounter++));
                                        t.setDaemon(true);
                                        mustStart = true;
+                                       miss = true;
                                }
                        }
                        synchronized(t) {
@@ -48,6 +58,10 @@
                                t.start();
                                synchronized(this) {
                                        runningThreads.add(t);
+                                       if(miss)
+                                               jobMisses++;
+                                       if(logMINOR)
+                                               Logger.minor(this, "Jobs: 
"+jobMisses+" misses of "+jobCount);
                                }
                        }
                        return;
@@ -70,6 +84,7 @@
                }

                public void run() {
+                       long ranJobs = 0;
                        while(true) {
                                Runnable job;

@@ -102,6 +117,8 @@
                                                waitingThreads.remove(this);
                                                if(!alive) {
                                                        
runningThreads.remove(this);
+                                                       if(logMINOR)
+                                                               
Logger.minor(this, "Exiting having executed "+ranJobs+" jobs : "+this);
                                                        return;
                                                }
                                        }
@@ -113,6 +130,7 @@
                                } catch (Throwable t) {
                                        Logger.error(this, "Caught "+t+" 
running job "+job, t);
                                }
+                               ranJobs++;
                        }
                }



Reply via email to