Java Reference
In-Depth Information
New static methods include these:
comparingInt , comparingDouble , comparingLong —Work like the comparing method but take
a function specialized for primitive types (respectively ToIntFunction , ToDoubleFunction , and
ToLongFunction ).
naturalOrder —Returns a Comparator object that imposes a natural order on Comparable
objects.
nullsFirst , nullsLast —Return a Comparator object that considers null to be less than non- null or
greater than non- null .
reverseOrder— Equivalent to naturalOrder().reversed() .
B.2. Concurrency
Java 8 brings several updates related to concurrency. The first is, of course, the introduction of
parallel streams, which we explore in chapter 7 . There's also the introduction of the
CompletableFuture class, which you can learn about in chapter 11 .
There are other noticeable updates. For example, the Arrays class now supports parallel
operations. We discuss these operations in section B.3 .
In this section, we look at updates in the java.util.concurrent.atomic package, which deals with
atomic variables. In addition, we discuss updates to the Concurrent-HashMap class, which
supports several new methods.
B.2.1. Atomic
The java.util.concurrent.atomic package offers several numeric classes, such as AtomicInteger
and AtomicLong that support atomic operation on single variables. They were updated to
support new methods:
getAndUpdate —Atomically updates the current value with the results of applying the given function,
returning the previous value.
updateAndGet —Atomically updates the current value with the results of applying the given function,
returning the updated value.
getAndAccumulate —Atomically updates the current value with the results of applying the given
function to the current and given values, returning the previous value.
accumulateAndGet —Atomically updates the current value with the results of applying the given
function to the current and given values, returning the updated value.
 
Search WWH ::




Custom Search