Parallel Operations

With the addition of Lambda expressions to arrays operations, Java introduced a key concept into the language of internal iteration. Essentially as developers we’re used to use loop operations as one of the most basic programming idioms, right up there with if and else.

The introduction of Lambda expressions turned that paradigm around with the actual iteration over a collection over which a Lambda function is invoked is carried out by the core library.

You can think of this as an extension of iterators where the actual operation of extracting the next item from a collection on which to operate is carried out by an iterator. An exciting possibility opened by this design pattern is to enable operations carried out on long arrays such as sorting, filtering and mapping to be carried out in parallel by the framework. When dealing with server code that’s processing lengthy collections on a continuous basis, this can lead to major throughput improvements with relative work from your end.

Here’s the same snippet as above, but using the framework’s new parallel processing capabilities -

ConcurrentMap<Person.Sex, List<Person>> byGender =

roster.parallelStream().collect(

Collectors.groupingByConcurrent(Person::getGender))


要查看或添加评论,请登录

Amit Rai的更多文章

  • Difference between array and arraylist #java

    Difference between array and arraylist #java

    I. Size: Array in Java is fixed in size.

  • Java Stream API for Bulk Data Operations on Collections

    Java Stream API for Bulk Data Operations on Collections

    A new java.util.

  • Nashorn

    Nashorn

    Nashorn: A Next-Generation JavaScript Engine for the JVM by Julien Ponge Scenarios for using Oracle Nashorn as a…

  • CLUSTER

    CLUSTER

    A single instance of Node.js runs in a single thread.

  • RxJS

    RxJS

    What is RxJS? RxJS or Reactive Extensions for JavaScript is a library for transforming, composing, and querying streams…

  • HTTP/2 vs HTTP 1.x

    HTTP/2 vs HTTP 1.x

    Let’s take a look at the key differences compared to HTTP 1.x and what issue each improvement is addressing: HTTP/2 is…

  • Concurrent Accumulators

    Concurrent Accumulators

    One of the most common scenarios in concurrent programming is updating of numeric counters accessed by multiple…

  • Garbage-First Garbage Collector

    Garbage-First Garbage Collector

    The Garbage-First (G1) garbage collector is a server-style garbage collector, targeted for multiprocessor machines with…

  • Exception Propagation

    Exception Propagation

    After a method throws an exception, the runtime system searches the call stack for a method that contains a block of…

  • Microbenchmarks

    Microbenchmarks

    Microbenchmarks are coming The Java Microbenchmarking Harness (JMH) by Alexey Shipilev is taking the next step in its…

社区洞察

其他会员也浏览了