Concurrency in Computationally Intensive Apps
The number of cores has a greater influence on the speedup of computation-intensive applications than on IO-bound applications, as we’ll see in this section. The example we’ll use is very simple; however, it has a hidden surprise—the uneven workload will affect the speedup.
Let’s write a program to compute the number of primes between 1 and 10 million. Let’s first solve this sequentially, and then we’ll solve it concurrently.
Sequential Computation of Prime Numbers
Let’s start with the abstract class AbstractPrimeFinder, which will help group some common methods for the problem at hand. The isPrime method will tell whether a given number is prime, and the countPrimesInRange method uses it to count ...
Get Programming Concurrency on the JVM now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.