Author: michiel
Date: 2010-07-01 14:29:29 +0200 (Thu, 01 Jul 2010)
New Revision: 42771

Modified:
   mmbase/trunk/utils/src/main/java/org/mmbase/util/ThreadPools.java
Log:
catching exceptions in static init makes them easier traceable

Modified: mmbase/trunk/utils/src/main/java/org/mmbase/util/ThreadPools.java
===================================================================
--- mmbase/trunk/utils/src/main/java/org/mmbase/util/ThreadPools.java   
2010-07-01 12:28:59 UTC (rev 42770)
+++ mmbase/trunk/utils/src/main/java/org/mmbase/util/ThreadPools.java   
2010-07-01 12:29:29 UTC (rev 42771)
@@ -112,6 +112,7 @@
      */
     public static final ThreadPoolExecutor jobsExecutor = new 
ThreadPoolExecutor(2, 2000, 1 * 60 , TimeUnit.SECONDS, new 
SynchronousQueue<Runnable>(), new ThreadFactory() {
 
+            @Override
             public Thread newThread(Runnable r) {
                 return ThreadPools.newThread(r, "JobsThread-" + (jobsSeq++));
             }
@@ -151,39 +152,49 @@
                 return ThreadPools.newThread(r, "SchedulerThread-" + 
(schedSeq++));
             }
         });
+
+    private static final Map<String, ExecutorService> threadPools = new 
ConcurrentHashMap<String, ExecutorService>();
+
     static {
         scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
 
 
-        EventManager.getInstance().addEventListener(new SystemEventListener() {
-                @Override
-                public void notify(SystemEvent systemEvent) {
-                    if (systemEvent instanceof SystemEvent.MachineName) {
+        try {
+            EventManager manager = EventManager.getInstance();
 
-                        String machineName = ((SystemEvent.MachineName) 
systemEvent).getName();
-                        for (WeakReference<Thread> tr : nameLess) {
-                            Thread t = tr.get();
-                            if (t != null) {
-                                String stringBefore = "" + t;
-                                t.setName(machineName + t.getName());
-                                log.debug("Fixed name of " + stringBefore + " 
-> " + t);
+            if (manager == null) {
+                log.fatal("No event manager!");
+
+            } else {
+
+                manager.addEventListener(new SystemEventListener() {
+                        @Override
+                        public void notify(SystemEvent systemEvent) {
+                            if (systemEvent instanceof 
SystemEvent.MachineName) {
+
+                                String machineName = 
((SystemEvent.MachineName) systemEvent).getName();
+                                for (WeakReference<Thread> tr : nameLess) {
+                                    Thread t = tr.get();
+                                    if (t != null) {
+                                        String stringBefore = "" + t;
+                                        t.setName(machineName + t.getName());
+                                        log.debug("Fixed name of " + 
stringBefore + " -> " + t);
+                                    }
+                                }
+                                nameLess.clear();
+                            } else if (systemEvent instanceof 
SystemEvent.Shutdown) {
+                                ThreadPools.shutdown();
                             }
                         }
-                        nameLess.clear();
-                    } else if (systemEvent instanceof SystemEvent.Shutdown) {
-                        ThreadPools.shutdown();
-                    }
-                }
-            });
-    }
+                    });
+            }
+            threadPools.put("jobs", jobsExecutor);
+            threadPools.put("filters", filterExecutor);
+            threadPools.put("schedules", scheduler);
+        } catch (Throwable t) {
+            log.fatal(t.getMessage(), t);
+        }
 
-
-    private static final Map<String, ExecutorService> threadPools = new 
ConcurrentHashMap<String, ExecutorService>();
-    static {
-        threadPools.put("jobs", jobsExecutor);
-        threadPools.put("filters", filterExecutor);
-        threadPools.put("schedules", scheduler);
-
     }
 
     public static Map<String, ExecutorService> getThreadPools() {
@@ -192,6 +203,7 @@
 
 
     static final UtilReader properties = new UtilReader("threadpools.xml", new 
Runnable() {
+            @Override
             public void run() {
                 configure();
             }

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

Reply via email to