Concurrent Programming in Java

Concurrent Programming in Java

Concurrent Programming in Java

Rice University

About this course: This course teaches learners (industry professionals and students) the fundamental concepts of concurrent programming in the context of Java 8. Concurrent programming enables developers to efficiently and correctly mediate the use of shared resources in parallel programs. By the end of this course, you will learn how to use basic concurrency constructs in Java such as threads, locks, critical sections, atomic variables, isolation, actors, optimistic concurrency and concurrent collections, as well as their theoretical foundations (e.g., progress guarantees, deadlock, livelock, starvation, linearizability).
Why take this course?
• It is important for you to be aware of the theoretical foundations of concurrency to avoid common but subtle programming errors.
• Java 8 has modernized many of the concurrency constructs since the early days of threads and locks.
• During the course, you will have online access to the instructor and mentors to get individualized answers to your questions posted on the forums.
• Each of the four modules in the course includes an assigned mini-project that will provide you with the necessary hands-on experience to use the concepts learned in the course on your own, after the course ends.
The desired learning outcomes of this course are as follows:
• Concurrency theory: progress guarantees, deadlock, livelock, starvation, linearizability
• Use of threads and structured/unstructured locks in Java
• Atomic variables and isolation
• Optimistic concurrency and concurrent collections in Java (e.g., concurrent queues, concurrent hashmaps)
• Actor model in Java
Mastery of these concepts will enable you to immediately apply them in the context of concurrent Java programs, and will also help you master other concurrent programming system that you may encounter in the future (e.g., POSIX threads, .NET threads).

Who is this class for: The course is targeted at an audience that is already familiar with sequential programming in Java, including a basic knowledge of Java 8 lambdas. In addition, we assume that each student has access to a laptop/desktop computer with a recent installation of Java 8. The course site includes instructions on how to obtain this installation, if needed.

Welcome to Concurrent Programming in Java! This course is designed as a three-part series and covers a theme or body of knowledge through various video lectures, demonstrations, and coding projects.

1 video, 5 readings

Video: Course Welcome

Reading: General Course Info

Reading: Course Icon Legend

Reading: Discussion Forum Guidelines

Discussion Prompt: Get to Know Your Classmates!

Reading: Pre-Course Survey

Reading: Mini Project 0: Setup

Ungraded Programming: Mini Project 0 Submission

Threads and Locks

In this module, we will learn about threads and locks, which have served as primitive building blocks for concurrent programming for over five decades. All computing platforms today include some form of support for threads and locks, and make them available for use by developers in a wide range of programming languages. We will learn how threads can be created, joined, and synchronized using structured (e.g., synchronized statements/methods) and unstructured (e.g., java.util.concurrent libraries) locks in Java. We will also learn about new classes of bugs that can arise when concurrent programs need to access shared resources. These bugs are referred to as violations of liveness/progress guarantees, and include deadlock, livelock, and starvation. We will conclude this module by studying different solutions to the classical "Dining Philosophers" problem, and use these solutions to illustrate instances of deadlock, livelock and starvation.

6 videos, 6 readings

Video: 1.1 Threads

Reading: 1.1 Lecture Summary

Video: 1.2 Structured Locks

Reading: 1.2 Lecture Summary

Video: 1.3 Unstructured Locks

Reading: 1.3 Lecture Summary

Video: 1.4 Liveness

Reading: 1.4 Lecture Summary

Video: 1.5 Dining Philosophers

Reading: 1.5 Lecture Summary

Reading: Mini Project 1: Locking and Synchronization

Video: Demonstration: Locking and Synchronization

Graded: Mini Project 1 Submission

Graded: Module 1 Quiz

WEEK 2

Critical Sections and Isolation

In this module, we will learn different approaches to coordinating accesses to shared resources without encountering the deadlock or livelock bugs studied earlier. Critical/isolated sections are higher-level concurrent programming constructs (relative to locks) that simplify the implementation of mutual exclusion by guaranteeing the absence of deadlocks and livelocks. Object-based isolation relaxes the constraints imposed by critical sections by allowing mutual exclusion to be specified on a per-object basis, as illustrated in the Spanning Tree example. Java's atomic variables represent an important, but restricted, case of object-based isolation that is implemented efficiently on all hardware platforms. Finally, we will learn how object-based isolation can be further relaxed with read/write access modes.

6 videos, 6 readings

Video: 2.1 Critical Sections

Reading: 2.1 Lecture Summary

Video: 2.2 Object Based Isolation (Monitors)

Reading: 2.2 Lecture Summary

Video: 2.3 Concurrent Spanning Tree Algorithm

Reading: 2.3 Lecture Summary

Video: 2.4 Atomic Variables

Reading: 2.4 Lecture Summary

Video: 2.5 Read, Write Isolation

Reading: 2.5 Lecture Summary

Reading: Mini Project 2: Global and Object-Based Isolation

Video: Demonstration: Global and Object-Based Isolation

Graded: Mini Project 2 Submission

Graded: Module 2 Quiz

Talking to Two Sigma: Using it in the Field

Join Professor Vivek Sarkar as he talks with Software Engineer, Dr. Shams Imam, at their downtown Houston, Texas office about threads, locks, deadlocks, high-level and low-level constructs, and the importance of concurrent programming.

In this module, we will learn another high-level approach to concurrent programming called the "Actor" model. A major difference between the Actor model and the Isolated Sections model is that there are no data races possible in the Actor model because it does not allow for any form of shared variables. However, as in all concurrent programming models, higher-level forms of nondeterminism are still possible in the Actor model due to an inherent asynchrony in the order in which messages may be delivered. We will study multiple examples of concurrency using the Actor model, including the classical Sieve of Eratosthenes algorithm to generate prime numbers, as well as producer-consumer patterns with both unbounded and bounded buffers.

In this module, we will study Concurrent Data Structures, which form an essential software layer in all multithreaded programming systems. First, we will learn about Optimistic Concurrency, an important multithreaded pattern in which two threads can "optimistically" make progress on their assigned work without worrying about mutual conflicts, and only checking for conflicts before "committing" the results of their work. We will then study the widely-used Concurrent Queue data structure. Even though the APIs for using concurrent queues are very simple, their implementations using the Optimistic Concurrency model can be complex and error-prone. To that end, we will also learn the formal notion of Linearizability to better understand correctness requirements for concurrent data structures. We will then study Concurrent Hash Maps, another widely-used concurrent data structure. Finally, we discuss a concurrent algorithm for finding a Minimum Spanning Tree of an undirected graph, an algorithm that relies on the use of Concurrent Data Structures under the covers.

Continue Your Journey with the Specialization "Parallel, Concurrent, and Distributed Programming in Java"

The next two videos will showcase the importance of learning about Parallel Programming and Distributed Programming in Java. Professor Vivek Sarkar will speak with industry professionals at Two Sigma about how the topics of our other two courses are utilized in the field.

Each course is like an interactive textbook, featuring pre-recorded videos, quizzes and projects.

Help from Your Peers

Connect with thousands of other learners and debate ideas, discuss course material,
and get help mastering concepts.

Certificates

Earn official recognition for your work, and share your success with friends,
colleagues, and employers.

Creators

Rice University

Rice University is consistently ranked among the top 20 universities in the U.S. and the top 100 in the world. Rice has highly respected schools of Architecture, Business, Continuing Studies, Engineering, Humanities, Music, Natural Sciences and Social Sciences and is home to the Baker Institute for Public Policy.