You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "turboFei (via GitHub)" <gi...@apache.org> on 2023/11/20 08:44:23 UTC

Re: [PR] Tolerate execeptions for periodical scheduled tasks [kyuubi]

turboFei commented on code in PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#discussion_r1398820709


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/util/ThreadUtils.scala:
##########
@@ -109,4 +109,28 @@ object ThreadUtils extends Logging {
     thread.setUncaughtExceptionHandler(NamedThreadFactory.kyuubiUncaughtExceptionHandler)
     thread.start()
   }
+
+  /**
+   * Schedule a runnable to the scheduled executor service.
+   * The exceptions thrown in the runnable will be caught and logged.
+   */
+  def scheduleTolerableRunnableWithFixedDelay(
+      scheduler: ScheduledExecutorService,
+      runnable: Runnable,
+      initialDelay: Long,
+      delay: Long,
+      timeUnit: TimeUnit,
+      errorMessageHint: String): Unit = {
+    scheduler.scheduleWithFixedDelay(
+      () =>
+        try {
+          runnable.run()
+        } catch {
+          case e: Exception =>
+            error(s"Error in $errorMessageHint", e)

Review Comment:
   ```
   case e: Throwable => error(s"Uncaught exception in thread ${Thread.currentThread().getName}", t)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org