Exercises 3
k) To obtain a parallel stream, simply invoke method on an existing stream.
l) Among its many features a CompletableFuture enables you to asynchronously execute
that perform tasks or that return values.
23.3 State whether each of the following is true or false. If false, explain why.
a) A thread is not runnable if it has terminated.
b) Some operating systems use timeslicing with threads. Therefore, they can enable threads
to preempt threads of the same priority.
c) When the thread’s quantum expires, the thread returns to the running state as the op-
erating system assigns it to a processor.
d) On a single-processor system without timeslicing, each thread in a set of equal-priority
threads (with no other threads present) runs to completion before other threads of equal
priority get a chance to execute.
23.4 (Advanced Optional Sections) State whether each of the following is true or false. If false,
explain why.
a) To determine the difference between two Instants, use class Duration’s static method
difference, which returns a Duration object containing the time difference.
b) Streams are easy to parallelize, enabling programs to benefit from enhanced perfor-
c) Interface Supplier, like interface Callable, is a functional interface with a single meth-
od that receives no arguments and returns a result.
d) CompletableFuture static method runAsync asynchronously executes a Supplier task
that returns a value.
e) CompletableFuture static method supplyAsync asynchronously executes a Runnable
task that does not return a result.
Exercises
NOTE: Solutions to the programming exercises are located in the ch23solutions folder.
Each exercise has its own folder named ex23_## where ## is a two-digit number represent-
ing the exercise number. For example, exercise 23.10’s solution is located in the folder
ex20_10.
23.5 (True or False) State whether each of the following is true or false. If false, explain why.
a) Method sleep does not consume processor time while a thread sleeps.