The Treacherous Paths to Concurrency

A quick look at the Activity Monitor on my system shows that while one core is super busy running the code, the other cores are sitting around sipping iced tea. Since this program is I/O intensive, we can get better performance if we throw a few threads at the problem and make use of those other cores.

Put on your Java hat for a minute and think about ways to make the code faster. The mere thought of using the JDK concurrency library can be quite nerve-wracking. Starting threads is not really hard, only clumsy—you’d use the executors to create a pool for threads. You can schedule exploring different subdirectories to threads from the pool. But the problem stems from the two variables—the shared mutable variables. ...

Get Pragmatic Scala 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.