curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [2/8] curator git commit: Added an unhandled exception error handler
Date Sun, 17 Jan 2016 22:26:42 GMT
Added an unhandled exception error handler


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/9951d4ec
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/9951d4ec
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/9951d4ec

Branch: refs/heads/master
Commit: 9951d4eceecdd97e73291c061ba04ec114ed9e53
Parents: 003acc6
Author: randgalt <randgalt@apache.org>
Authored: Thu Jan 14 22:37:24 2016 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Thu Jan 14 22:37:24 2016 -0500

----------------------------------------------------------------------
 .../java/org/apache/curator/utils/ThreadUtils.java   | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/9951d4ec/curator-client/src/main/java/org/apache/curator/utils/ThreadUtils.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/utils/ThreadUtils.java b/curator-client/src/main/java/org/apache/curator/utils/ThreadUtils.java
index 24efd50..74b4e40 100644
--- a/curator-client/src/main/java/org/apache/curator/utils/ThreadUtils.java
+++ b/curator-client/src/main/java/org/apache/curator/utils/ThreadUtils.java
@@ -18,7 +18,10 @@
  */
 package org.apache.curator.utils;
 
+import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -26,6 +29,8 @@ import java.util.concurrent.ThreadFactory;
 
 public class ThreadUtils
 {
+    private static final Logger log = LoggerFactory.getLogger(ThreadUtils.class);
+
     public static void checkInterrupted(Throwable e)
     {
         if ( e instanceof InterruptedException )
@@ -61,9 +66,19 @@ public class ThreadUtils
 
     public static ThreadFactory newGenericThreadFactory(String processName)
     {
+        Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler()
+        {
+            @Override
+            public void uncaughtException(Thread t, Throwable e)
+            {
+                log.error("Unexpected exception in thread: " + t, e);
+                Throwables.propagate(e);
+            }
+        };
         return new ThreadFactoryBuilder()
             .setNameFormat(processName + "-%d")
             .setDaemon(true)
+            .setUncaughtExceptionHandler(uncaughtExceptionHandler)
             .build();
     }
 


Mime
View raw message