O'Reilly logo
live online training icon Live Online training

Essentials of JVM Threading

Simon Roberts

Modern computers are not getting much faster, but are gaining more CPU cores. To use these to the benefit of your program’s performance, you must create software that runs on multiple threads. However, writing reliable, threadsafe, programs is notoriously difficult. This course introduces the essential knowledge about threading on a JVM that will allow you to build threaded programs, recognize the pitfalls, and use one of two popular approaches to creating safe code.

This course will give you the knowledge to understand JVM threading and then construct your software in a way that can benefit from it.

What you'll learn-and how you can apply it

  • Create simple concurrent programs in Java
  • Understand the problems of concurrent execution, and use of Threads, and introduces
  • Learn the low level support provided by the JVM for creating predictable concurrent programs
  • Practical use of higher level constructs in the Java concurrency API
  • Design and implement the producer-consumer model
  • How to use ExecutorServices and thread pools
  • How to use Java’s “promise” API, the CompletableFuture

This training course is for you because...

  • You want to build practical programs that benefit from modern hardware that has multiple CPU cores.
  • You want to improve your understanding of the pitfalls of concurrent execution of code on a JVM.
  • You are working with a multi-threaded program written for the JVM, and need a better understanding of its possible failure modes.

Prerequisites

  • You should be comfortable with core Java language syntax and semantics as examples will be created in that language.
  • Source code repository on github.com will be used to distribute examples, diagrams, and other materials created during the course

Recommended Prep:

About your instructor

  • Simon started out working as a software engineer, specializing in industrial control systems, and had a sideline teaching for a local University in his then-home-town of Cambridge, England.

    In 1995 he joined Sun Microsystems, Inc. as a senior instructor and course developer. Simon spearheaded the introduction of Java training by Sun Microsystems in the U.K. in 1995. He developed the first Java certification exams for Sun before he moved to the U.S. in 1998.

    Since leaving Sun in 2004, Simon has developed and delivered training for clients around the world.

    Simon believes that training should have an immediate purpose and application, and that the most effective training is usually "on the job" mentoring, helping to remove the immediate roadblocks to productivity that so often plague workers in fast moving environments.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Threading is easy--unless you want them to do something useful (20m)

  • Building a first thread
  • Identifying a first problem--shared mutable state

Understanding three key problems (40m)

  • Visibility
  • Transactional integrity
  • Timing

Break (10m)

Overview of the JVM’s low-level tools (60m)

  • “Happens-Before” relationships
  • volatile
  • synchronized
  • wait, notify, notifyAll
  • Example problems using low-level features
  • “Memory consistency effects” in the java.util.concurrent package

Break (10m)

A simple, universal, solution to all threading problems (30m)

  • Principles and practice of the solution
  • How the solution solves all our problems
  • Drawbacks of the solution

Essentials of the ExecutorService Thread pools (30m)

Break (10m)

Essentials of the CompletableFuture (Java’s “Promise” API) (30m)