5 Java concurrency fundamentals

 

This chapter covers

  • Concurrency theory
  • Block-structured concurrency
  • Synchronization
  • The Java Memory Model (JMM)
  • Concurrency support in bytecode

Java has two, mostly separate concurrency APIs: the older API, which is usually called block-structured concurrency or synchronization-based concurrency or even “classic concurrency,” and the newer API, which is normally referred to by its Java package name, java.util.concurrent.

In this book, we’re going to talk about both approaches. In this chapter, we’ll begin our journey by looking at the first of these two approaches. After that, in the next chapter, we’ll introduce java.util.concurrent. Much later, we’ll return to the subject of concurrency in chapter 16, “Advanced Concurrent Programming,” which discusses advanced techniques, concurrency in non-Java JVM languages, and the interplay between concurrency and functional programming.

Let’s get started and meet the classic approach to concurrency. This was the only API available until Java 5. As you might guess from the alternative name, “synchronization-based concurrency,” this is the language-level API that is built into the platform and depends upon the synchronized and volatile keywords.

It is a low-level API and can be somewhat difficult to work with, but it is very much worth understanding. It provides a solid foundation for the chapters later in the book that explain other types and aspects of concurrency.

5.1 Concurrency theory primer

5.1.1 But I already know about Thread

5.1.2 Hardware

5.1.3 Amdahl’s law

5.1.4 Explaining Java’s threading model

5.1.5 Lessons learned

5.2 Design concepts

5.2.1 Safety and concurrent type safety

5.2.2 Liveness

5.2.3 Performance

sitemap