[ASTERIXDB-2121][HYR] Handle Throwables during job execution
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
Currently, only exceptions are handled and logged during Hyracks job
execution. However, throwables, such as errors, are not handled and
simply ignored saliently. This patch handles all throwabls during job
execution.
Change-Id: Ibbe09d5231fe2bdfa12d834bb1a6adb46b355a48
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2051
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/utils/HyracksThreadFactory.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/utils/HyracksThreadFactory.java
index 52631bf..c9ef4d08 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/utils/HyracksThreadFactory.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/utils/HyracksThreadFactory.java
@@ -18,13 +18,18 @@
*/
package org.apache.hyracks.control.common.utils;
+import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class HyracksThreadFactory implements ThreadFactory {
private final String identifier;
private final AtomicInteger threadId = new AtomicInteger();
+ private static final Logger LOGGER = Logger.getLogger(HyracksThreadFactory.class.getName());
+
public HyracksThreadFactory(String identifier) {
this.identifier = identifier;
}
@@ -33,6 +38,12 @@
public Thread newThread(Runnable runnable) {
Thread t = new Thread(runnable, "Executor-" + threadId.incrementAndGet() + ":" + identifier);
t.setDaemon(true);
+ t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
+ @Override
+ public void uncaughtException(Thread t, Throwable e) {
+ LOGGER.log(Level.SEVERE, "Uncaught exception by " + t.getName(), e);
+ }
+ });
return t;
}
}