Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.ui

import java.util.concurrent.Semaphore

import scala.util.Random

import org.apache.spark.{SparkConf, SparkContext}
Expand Down Expand Up @@ -88,6 +90,8 @@ private[spark] object UIWorkloadGenerator {
("Job with delays", baseData.map(x => Thread.sleep(100)).count)
)

val barrier = new Semaphore(-nJobSet * jobs.size + 1)

(1 to nJobSet).foreach { _ =>
for ((desc, job) <- jobs) {
new Thread {
Expand All @@ -99,12 +103,17 @@ private[spark] object UIWorkloadGenerator {
} catch {
case e: Exception =>
println("Job Failed: " + desc)
} finally {
barrier.release()
}
}
}.start
Thread.sleep(INTER_JOB_WAIT_MS)
}
}

// Waiting for threads.
barrier.acquire()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just join() on all of those threads?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because I didn't think it's simple to use join(); we need to allocate array for those threads and the main thread should call for each thread in the array.

But, I also think it's simpler to use CounDownLatch instead of Semaphore right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah. Well I don't have a strong opinion either way. Either count down latch or semaphore is fine.

sc.stop()
}
}