Answer the question
In order to leave comments, you need to log in
Why is the program terminating?
object test {
def main(args: Array[String]) {
val buf: ArrayBlockingQueue[Integer] = new ArrayBlockingQueue(5)
for (p <- 1 to 2)
ExecutionContext.global.execute(() =>
for (i <- 1 to 10) {println(s"Producer$p producing $i"); buf.put(i)}
)
for (c <- 1 to 3)
ExecutionContext.global.execute(() =>
for (i <- 1 to 10) {println(s"Consumer$c consumed ${buf.take}")}
)
Thread.sleep(1000)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question