Make Your CPU Cores Sweat with Parallel Streams
summary
Explains how Java 8 parallel streams run on the common ForkJoinPool (threads ~= CPU cores), use the fork/join framework and Spliterator.trySplit to divide work, and often give real wins (example shows ~5x speedup for a CPU-heavy pipeline) but also real hazards: linked lists and iterative generators split poorly and boxing can double cost, and a naive attempt to sum 1 billion boxed elements can 1 billion crash the JVM heap; avoid shared mutable accumulators, prefer CPU-bound, measurable changes.
AI-written summary · about
chapters (16)
- 0:00Intro
- 0:37What is CERN?
- 2:20Manipulating collections before Java 8
- 4:04Manipulating data with streams
- 6:03Threads (JDK 1) Invocation of a thread results in a new path of execution Thread API is still great for simple asynchronous tasks and background processing
- 7:05Executor Service (JDK 5) Java 5 introduced several new APIs that simplify design and development of multi-thread applications
- 8:18Parallel Streams (JDK 8) The Stream library enables you to execute operations in parallel without much effort Under the hood it employs the forkjoin framework and the Spliterator
- 11:58Fork/Join Framework (JDK7) Fork
- 18:58F/J Framework and Parallel Streams
- 20:53Custom F/J Pool for a Parallel Stream(s)?
- 30:30Decomposing LinkedList and ArrayList Always take into account how well the stream source decomposes
- 33:09Decomposing various stream sources
- 34:12Decomposability and Auto(un)boxing
- 36:33findAny () and unordered ()
- 41:54sequential() and parallel()
- 44:24Conclusions
related talks
01h 01mFrom Concurrent to Parallel
50mFrom Concurrent to Parallel
02h 35mParallel and Asynchronous Programming with Streams and CompletableFuture
01h 00mLet’s Get to the Rapids: Java 8 Stream Performance
47mWhen Greed Is Good: Understanding Java Stream Performance
47mStreams – Below the Surface
54mParallel-Ready Java Code: Managing Mutation in an Imperative Language
53mTurbo Charge CPU Utilization in Fork/Join Using the ManagedBlocker
