The order of lines in output

Report a typo

Here's a code snippet that creates an executor and submits two tasks to it:

fun main() {

    val executor: ExecutorService = Executors.newFixedThreadPool(4)

    for (i in 1..2) {
        val taskNumber: Int = i
        executor.submit { println("Starting task-$taskNumber") }
    }

    TimeUnit.MILLISECONDS.sleep(50) // the current thread waits for 50 ms

    executor.shutdown()

    println("Main completed")
}

Here is the output of one execution of the program:

Main completed
Starting task-1
Starting task-2

Select one correct statement about the order of lines in the output.

Select one option from the list
___

Create a free account to access the full topic