This chapter covers
- Fork / Join
- 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 5. Our non-Java languages get a look in 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 as well.
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’ve seen in Chapter 6.
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 very 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.