Java Reference
In-Depth Information
d) Class implements the BlockingQueue interface using an array.
e) Class Instant 's static method gets the current time.
f) Duration method returns the Duration as a long value milliseconds.
g) NumberFormat static method
returns a NumberFormat that's used to format a
number as a percentage.
h) NumberFormat method
returns a String representation of its argument in the
specified numeric format.
i) Arrays static method fills an array with values produced by a generator function.
j) Arrays static method applies a BinaryOperator to the current and previous
array elements and stores the result in the current element.
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 Instant s, 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-
mance on multi-core systems.
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.
Answers to Self-Review Exercises
23.1 a) its run method ends. b) sleep , Thread . c) timed waiting . d) ready , running . e) Executor .
f) shutdown . g) producer/consumer, producer, consumer. h) synchronized .
23.2 a) signal . b) signalAll . c) await , waiting . d) ArrayBlockingQueue . e) now . f) toMillis .
g) getPercentInstance . h) format . i) parallelSetAll . j) parallelPrefix . k) parallel . l) Runna-
ble s, Supplier s.
23.3 a) True. b) False. Timeslicing allows a thread to execute until its timeslice (or quantum)
expires. Then other threads of equal priority can execute. c) False. When a thread's quantum ex-
pires, the thread returns to the ready state and the operating system assigns to the processor another
thread. d) True.
23.4 a) False. The Duration method for calculating the difference between two Instant s is
named between . b) True. c) True. d) False. The method that asynchronously executes a Supplier is
supplyAsync . e) False. The method that asynchronously executes a Runnable is runAsync .
Search WWH ::




Custom Search