Yuta HIGUCHI

Attempt to keep record of uncaught Exception

Change-Id: I0da6aae52c758dd14ccd47c8865827e814f05a58
...@@ -15,16 +15,21 @@ ...@@ -15,16 +15,21 @@
15 */ 15 */
16 package org.onlab.util; 16 package org.onlab.util;
17 17
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
18 import java.io.BufferedReader; 20 import java.io.BufferedReader;
19 import java.io.File; 21 import java.io.File;
20 import java.io.FileInputStream; 22 import java.io.FileInputStream;
21 import java.io.IOException; 23 import java.io.IOException;
22 import java.io.InputStreamReader; 24 import java.io.InputStreamReader;
25 +import java.lang.Thread.UncaughtExceptionHandler;
23 import java.nio.charset.StandardCharsets; 26 import java.nio.charset.StandardCharsets;
24 import java.util.ArrayList; 27 import java.util.ArrayList;
25 import java.util.List; 28 import java.util.List;
26 import java.util.concurrent.ThreadFactory; 29 import java.util.concurrent.ThreadFactory;
27 30
31 +import org.slf4j.Logger;
32 +
28 import com.google.common.base.Strings; 33 import com.google.common.base.Strings;
29 import com.google.common.primitives.UnsignedLongs; 34 import com.google.common.primitives.UnsignedLongs;
30 import com.google.common.util.concurrent.ThreadFactoryBuilder; 35 import com.google.common.util.concurrent.ThreadFactoryBuilder;
...@@ -34,6 +39,8 @@ public abstract class Tools { ...@@ -34,6 +39,8 @@ public abstract class Tools {
34 private Tools() { 39 private Tools() {
35 } 40 }
36 41
42 + private static final Logger TOOLS_LOG = getLogger(Tools.class);
43 +
37 /** 44 /**
38 * Returns a thread factory that produces threads named according to the 45 * Returns a thread factory that produces threads named according to the
39 * supplied name pattern. 46 * supplied name pattern.
...@@ -42,7 +49,16 @@ public abstract class Tools { ...@@ -42,7 +49,16 @@ public abstract class Tools {
42 * @return thread factory 49 * @return thread factory
43 */ 50 */
44 public static ThreadFactory namedThreads(String pattern) { 51 public static ThreadFactory namedThreads(String pattern) {
45 - return new ThreadFactoryBuilder().setNameFormat(pattern).build(); 52 + return new ThreadFactoryBuilder()
53 + .setNameFormat(pattern)
54 + // FIXME remove UncaughtExceptionHandler before release
55 + .setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
56 +
57 + @Override
58 + public void uncaughtException(Thread t, Throwable e) {
59 + TOOLS_LOG.error("Uncaught exception on {}", t.getName(), e);
60 + }
61 + }).build();
46 } 62 }
47 63
48 /** 64 /**
......