jerryshao commented on a change in pull request #242: [LIVY-336] Livy should 
not spawn one thread per job to track the job on Yarn
URL: https://github.com/apache/incubator-livy/pull/242#discussion_r346095496
 
 

 ##########
 File path: server/src/main/scala/org/apache/livy/utils/SparkYarnApp.scala
 ##########
 @@ -98,7 +119,37 @@ object SparkYarnApp extends Logging {
     }
   }
 
-
+  private val yarnAppMonitorThread = new Thread() {
+    override def run() : Unit = {
+      val executor = Executors.newSingleThreadExecutor
+      while (true) {
+        for ((app, appTag) <- appMap) {
+          Future {
+            app.monitorLock.synchronized {
+              val handler = executor.submit(new Runnable {
+                override def run(): Unit = {
+                  app.monitorSparkYarnApp()
+                }
+              })
+              try {
+                // prevent the rpc block of one app from blocking all apps
+                handler.get(yarnAppMonitorTimeout, MILLISECONDS)
+              } catch {
+                case e: Exception => {
+                  handler.cancel(true)
+                  error(s"monitor app: ${appTag} exception:", e)
+                }
+              }
+              if (!app.isRunning) {
+                appMap -= app
+              }
+            }
+          }
+        }
+        Thread.sleep(yarnPollInterval)
 
 Review comment:
   We should consider interrupted exception here. It would be better to catch 
this exception and exit the infinite loop.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to