aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-04-24 17:25:47 +0100
committerLuck <git@lucko.me>2022-04-24 17:25:47 +0100
commitb077100667c1dee6e73da399e3484f92bbf67cb8 (patch)
treeefac3cb29cb4cdbb93ba7ab2ba2aac9b050731f2 /spark-common/src/main/java/me
parentda5a859adb7d25752dd0d3564fa15669242ae92f (diff)
downloadspark-b077100667c1dee6e73da399e3484f92bbf67cb8.tar.gz
spark-b077100667c1dee6e73da399e3484f92bbf67cb8.tar.bz2
spark-b077100667c1dee6e73da399e3484f92bbf67cb8.zip
Fix NPE caused by initialisation order on Forge/Fabric
Diffstat (limited to 'spark-common/src/main/java/me')
-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();
+ }
}