O'Reilly logo

Programming Concurrency on the JVM by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required