This is an automated email from the ASF dual-hosted git repository.
feiwang pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/branch-1.7 by this push:
new de8ebd700 [KYUUBI #4836] Set UncaughtExceptionHandler for thread to
log exception
de8ebd700 is described below
commit de8ebd7001abf67c3b4f91495753eec089f2a3dd
Author: fwang12 <[email protected]>
AuthorDate: Mon May 15 10:42:56 2023 +0800
[KYUUBI #4836] Set UncaughtExceptionHandler for thread to log exception
### _Why are the changes needed?_
To provide more insight, if there is uncaught exception.
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including
negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [x] [Run
test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests)
locally before make a pull request
Closes #4836 from turboFei/handler_exception.
Closes #4836
b9d304fb8 [fwang12] comment
3819447a6 [fwang12] un caughtt
Authored-by: fwang12 <[email protected]>
Signed-off-by: fwang12 <[email protected]>
(cherry picked from commit 61fcffb7d05f0bb3b2a945906c0d56c69b6f16e2)
Signed-off-by: fwang12 <[email protected]>
---
...adFactory.scala => KyuubiUncaughtExceptionHandler.scala} | 13 ++++++-------
.../scala/org/apache/kyuubi/util/NamedThreadFactory.scala | 7 +++++++
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git
a/kyuubi-common/src/main/scala/org/apache/kyuubi/util/NamedThreadFactory.scala
b/kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiUncaughtExceptionHandler.scala
similarity index 74%
copy from
kyuubi-common/src/main/scala/org/apache/kyuubi/util/NamedThreadFactory.scala
copy to
kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiUncaughtExceptionHandler.scala
index 89c3c96ea..69cfe207f 100644
---
a/kyuubi-common/src/main/scala/org/apache/kyuubi/util/NamedThreadFactory.scala
+++
b/kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiUncaughtExceptionHandler.scala
@@ -17,13 +17,12 @@
package org.apache.kyuubi.util
-import java.util.concurrent.ThreadFactory
+import java.lang.Thread.UncaughtExceptionHandler
-class NamedThreadFactory(name: String, daemon: Boolean) extends ThreadFactory {
- override def newThread(r: Runnable): Thread = {
- val t = new Thread(r)
- t.setName(name + ": Thread-" + t.getId)
- t.setDaemon(daemon)
- t
+import org.apache.kyuubi.Logging
+
+class KyuubiUncaughtExceptionHandler extends UncaughtExceptionHandler with
Logging {
+ override def uncaughtException(t: Thread, e: Throwable): Unit = {
+ error(s"Uncaught exception in thread ${t.getName}", e)
}
}
diff --git
a/kyuubi-common/src/main/scala/org/apache/kyuubi/util/NamedThreadFactory.scala
b/kyuubi-common/src/main/scala/org/apache/kyuubi/util/NamedThreadFactory.scala
index 89c3c96ea..13127b59b 100644
---
a/kyuubi-common/src/main/scala/org/apache/kyuubi/util/NamedThreadFactory.scala
+++
b/kyuubi-common/src/main/scala/org/apache/kyuubi/util/NamedThreadFactory.scala
@@ -20,10 +20,17 @@ package org.apache.kyuubi.util
import java.util.concurrent.ThreadFactory
class NamedThreadFactory(name: String, daemon: Boolean) extends ThreadFactory {
+ import NamedThreadFactory._
+
override def newThread(r: Runnable): Thread = {
val t = new Thread(r)
t.setName(name + ": Thread-" + t.getId)
t.setDaemon(daemon)
+ t.setUncaughtExceptionHandler(kyuubiUncaughtExceptionHandler)
t
}
}
+
+object NamedThreadFactory {
+ private val kyuubiUncaughtExceptionHandler = new
KyuubiUncaughtExceptionHandler
+}