From 96846d168d7f9f4e1cbe9414eff9606980d09828 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Mon, 20 Nov 2023 14:34:47 +0800 Subject: [PATCH] update --- .../session/SparkSQLSessionManager.scala | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSQLSessionManager.scala b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSQLSessionManager.scala index ea5066d7328..2528a348135 100644 --- a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSQLSessionManager.scala +++ b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSQLSessionManager.scala @@ -67,25 +67,27 @@ class SparkSQLSessionManager private (name: String, spark: SparkSession) if (!userIsolatedSparkSession) { userIsolatedSparkSessionThread = Some(ThreadUtils.newDaemonSingleThreadScheduledExecutor("user-isolated-cache-checker")) - scheduleTolerableRunnableWithFixedDelay( - _, - () => { - userIsolatedCacheLock.synchronized { - val iter = userIsolatedCacheCount.entrySet().iterator() - while (iter.hasNext) { - val kv = iter.next() - if (kv.getValue._1 == 0 && - kv.getValue._2 + userIsolatedIdleTimeout < System.currentTimeMillis()) { - userIsolatedCache.remove(kv.getKey) - iter.remove() + userIsolatedSparkSessionThread.foreach { thread => + scheduleTolerableRunnableWithFixedDelay( + thread, + () => { + userIsolatedCacheLock.synchronized { + val iter = userIsolatedCacheCount.entrySet().iterator() + while (iter.hasNext) { + val kv = iter.next() + if (kv.getValue._1 == 0 && + kv.getValue._2 + userIsolatedIdleTimeout < System.currentTimeMillis()) { + userIsolatedCache.remove(kv.getKey) + iter.remove() + } } } - } - }, - userIsolatedIdleInterval, - userIsolatedIdleInterval, - TimeUnit.MILLISECONDS, - "user-isolated-spark-session-cache-checker") + }, + userIsolatedIdleInterval, + userIsolatedIdleInterval, + TimeUnit.MILLISECONDS, + "user-isolated-spark-session-cache-checker") + } } }