16 Advanced concurrent programming

 

This chapter covers

  • The Fork/Join API
  • Work-stealing algorithms
  • Concurrency and functional programming
  • Under the hood with Kotlin coroutines
  • Clojure concurrency
  • Software transactional memory
  • Agents

In this chapter, we will bring together several themes from earlier chapters. In particular, we will weave together the functional programming concepts from previous chapters with the Java concurrency libraries from chapter 6. Our non-Java languages get included as well, with some novel concurrency aspects of both Kotlin and Clojure appearing later in the chapter.

Note

The concepts in this chapter, such as coroutines and agents (aka actors), are also increasingly part of the landscape of Java concurrency.

We’ll kick off with a slight oddity: the Java Fork/Join API. This framework allows a certain class of concurrent problems to be handled more efficiently than the executors we saw in chapter 6.

16.1 The Fork/Join framework

As we discussed in chapter 7, processor speeds (or, more properly, transistor counts on CPUs) have increased hugely in recent years. I/O performance has not had the same remarkable improvement, and so the end result is that waiting for I/O is now a common situation. This suggests that we could make better use of the processing capabilities inside our computers. The Fork/Join (F/J) framework is an attempt to do just that.

16.1.1 A simple F/J example

16.1.2 Parallelizing problems for F/J

16.1.3 Work-stealing algorithms

16.2 Concurrency and functional programming

16.2.1 CompletableFuture revisited

16.2.2 Parallel streams

16.3 Under the hood with Kotlin coroutines

sitemap