Author: michiel
Date: 2009-05-26 10:17:08 +0200 (Tue, 26 May 2009)
New Revision: 35432

Modified:
   mmbase/trunk/src/org/mmbase/util/ThreadPools.java
Log:
some time odd warnings. This avoids it.

Modified: mmbase/trunk/src/org/mmbase/util/ThreadPools.java
===================================================================
--- mmbase/trunk/src/org/mmbase/util/ThreadPools.java   2009-05-26 07:59:20 UTC 
(rev 35431)
+++ mmbase/trunk/src/org/mmbase/util/ThreadPools.java   2009-05-26 08:17:08 UTC 
(rev 35432)
@@ -101,11 +101,25 @@
      */
     public static final ThreadPoolExecutor jobsExecutor = new 
ThreadPoolExecutor(2, 200, 5 * 60 , TimeUnit.SECONDS, new 
ArrayBlockingQueue<Runnable>(300), new ThreadFactory() {
 
+            @Override
             public Thread newThread(Runnable r) {
                 return ThreadPools.newThread(r, "JobsThread-" + (jobsSeq++));
             }
-        });
+        }) {
+            @Override
+            public void execute(Runnable r) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Executing " + r + " because ", new Exception());
+                }
+                super.execute(r);
+            }
+            @Override
+            protected void beforeExecute(Thread t, Runnable r) {
+                log.debug("Now executing " + r + " in thread " + t);
 
+            }
+        };
+
     private static String getMachineName() {
         String machineName;
         try {
@@ -119,18 +133,7 @@
         return machineName;
     }
 
-    static {
-        jobsExecutor.execute(new Runnable() {
-                public void run() {
-                    String machineName = getMachineName();
-                    for (Thread t : nameLess) {
-                        t.setName(machineName + ":" + t.getName());
-                    }
-                }
-            });
-    }
 
-
     private static long schedSeq = 0;
     /**
      * This executor is for repeating tasks. E.g. every running
@@ -146,7 +149,21 @@
             }
         });
     static {
-        ((ScheduledThreadPoolExecutor) 
scheduler).setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
+        scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
+
+
+        // after some time the machine name will be known, use it for the 
'nameless' threads.
+        // Actually, getMachineName is starting to wait too, so I think the 
scheduled delay here is
+        // a bit silly, but otherwise I in some cases encountered an exception 
('cannot be started
+        // by this class').
+        scheduler.schedule(new Runnable() {
+                public void run() {
+                    String machineName = getMachineName();
+                    for (Thread t : nameLess) {
+                        t.setName(machineName + ":" + t.getName());
+                    }
+                }
+            }, 1, TimeUnit.MINUTES);
     }
 
     private static final Map<String, ExecutorService> threadPools = new 
ConcurrentHashMap<String, ExecutorService>();

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to