Jian Li
Committed by Gerrit Code Review

[ONOS-3528] Enable logging exception when Executor.execute invoked

Change-Id: I4df7c9a0bc0607c16c4c36103447ce8a8f14ffa7
...@@ -100,10 +100,31 @@ public abstract class Tools { ...@@ -100,10 +100,31 @@ public abstract class Tools {
100 * @return thread factory 100 * @return thread factory
101 */ 101 */
102 public static ThreadFactory groupedThreads(String groupName, String pattern) { 102 public static ThreadFactory groupedThreads(String groupName, String pattern) {
103 + return groupedThreads(groupName, pattern, log);
104 + }
105 +
106 + /**
107 + * Returns a thread factory that produces threads named according to the
108 + * supplied name pattern and from the specified thread-group. The thread
109 + * group name is expected to be specified in slash-delimited format, e.g.
110 + * {@code onos/intent}. The thread names will be produced by converting
111 + * the thread group name into dash-delimited format and pre-pended to the
112 + * specified pattern. If a logger is specified, it will use the logger to
113 + * print out the exception if it has any.
114 + *
115 + * @param groupName group name in slash-delimited format to indicate hierarchy
116 + * @param pattern name pattern
117 + * @param logger logger
118 + * @return thread factory
119 + */
120 + public static ThreadFactory groupedThreads(String groupName, String pattern, Logger logger) {
121 + if (logger == null) {
122 + return groupedThreads(groupName, pattern);
123 + }
103 return new ThreadFactoryBuilder() 124 return new ThreadFactoryBuilder()
104 .setThreadFactory(groupedThreadFactory(groupName)) 125 .setThreadFactory(groupedThreadFactory(groupName))
105 .setNameFormat(groupName.replace(GroupedThreadFactory.DELIMITER, "-") + "-" + pattern) 126 .setNameFormat(groupName.replace(GroupedThreadFactory.DELIMITER, "-") + "-" + pattern)
106 - .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on " + t.getName(), e)) 127 + .setUncaughtExceptionHandler((t, e) -> logger.error("Uncaught exception on " + t.getName(), e))
107 .build(); 128 .build();
108 } 129 }
109 130
......