Get the result

Report a typo

Suppose that you want to count the number of occurrences of a word in a large file. Since the operation can take a very long time, you decide to do it asynchronously in order to prevent blocking the main thread of the application.

You have the following code:

val executor = Executors.newSingleThreadExecutor()
val countWordInFile = Callable {
    var wordsCount = 0
    // accessing a file and calculating wordsCount
    wordsCount
}
val task = executor.submit(countWordInFile)

// some other statements here
TimeUnit.SECONDS.sleep(15)

val count = task.get()

What may happen after invoking the get method of task (the last line)?

Select all possible cases.

Select one or more options from the list
___

Create a free account to access the full topic