aboutsummaryrefslogtreecommitdiff
path: root/spark-common
diff options
context:
space:
mode:
Diffstat (limited to 'spark-common')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/util/SparkThreadFactory.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/SparkThreadFactory.java b/spark-common/src/main/java/me/lucko/spark/common/util/SparkThreadFactory.java
index 9c7309d..156fa0d 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/util/SparkThreadFactory.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/util/SparkThreadFactory.java
@@ -23,7 +23,7 @@ package me.lucko.spark.common.util;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
-public class SparkThreadFactory implements ThreadFactory {
+public class SparkThreadFactory implements ThreadFactory, Thread.UncaughtExceptionHandler {
private static final AtomicInteger poolNumber = new AtomicInteger(1);
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
@@ -36,7 +36,14 @@ public class SparkThreadFactory implements ThreadFactory {
public Thread newThread(Runnable r) {
Thread t = new Thread(r, this.namePrefix + this.threadNumber.getAndIncrement());
+ t.setUncaughtExceptionHandler(this);
t.setDaemon(true);
return t;
}
+
+ @Override
+ public void uncaughtException(Thread t, Throwable e) {
+ System.err.println("Uncaught exception thrown by thread " + t.getName());
+ e.printStackTrace();
+ }
}