Advances in Programming Languages 2018/19
Lecture 9Concurrency AbstractionsThis lecture reviews the built-in Java concurrency primitives from Lecture 8 and introduces some patterns that can help with using them: immutability, synchronization wrappers, and control abstractions like producer/consumer. More high-level currency abstractions, such as those in the java.util.concurrent package, support programming that is not only thread-safe but takes explicit advantage of concurrency to increase performance and responsiveness.
There are still pitfalls around, though: race conditions and in particular data races that may cause problems in concurrent code. The abstractions described earlier can help manage these challenges, but sometimes at a performance cost. At the end there is a brief walk-through of some some intentionally racy code from the Java String library. This is an example of a “benign” data race which improves performance and, the creators believe, does not introduce surprise behaviour.