Java Threads Demystified
Published by Pearson
An Introduction to Multithreading—Including Java 21 Virtual Threads
- Gain a firm understanding of the Java threading model
- Learn how to take advantage of threads – and when to avoid them
- Understand virtual threads, introduced in Java 21, and learn why they are so important
Modern computer architectures, which depend on multiple ultrafast cores, can only be fully utilized by multithreaded programs. But to write multithreaded code, you to have a basic understanding of threads, race conditions and how to avoid them, how threads can cooperate, and the ways to use the Java platform utilities built on top of them, like executors and the thread-safe collections.
This course will equip you with the introduction that you need in order to write multithreaded code, avoiding thread safety and performance issues, and it will provide you with the foundational knowledge for deeper exploration of this fascinating but difficult area.
What you’ll learn and how you can apply it
- Learn the basic features of threads: synchronization, interrupts, intrinsic and explicit locks
- Write simple thread-safe classes
- Use concurrent collections and executors
- Recognize the pitfalls and common types of bugs in multithreaded programs
- Virtual threads and when to use them
This live event is for you because...
- You’re a Java programmer who has briefly encountered threads and wants to know more
- You’re a Java programmer who knows the basics of threads and is prepared to go a little deeper
- You’re a Java programmer who wants practical knowledge about when and where to use multithreading, and how to avoid the potential pitfalls
Prerequisites
- Familiarity with Java syntax, at least to Java 11
- Some familiarity with the Java Collections Framework: ArrayList, HashMap, etc
Course Set-up
- Latest IntelliJ IDEA, either Community or Ultimate edition: see https://www.jetbrains.com/idea/download
- Latest OpenJDK – at least JDK 21 – see https://jdk.java.net/
Recommended Preparation
- Read: Core Java, Volume I: Fundamentals, 12th Edition, by Cay Horstmann
- Watch: Java Programming Essentials by Simon Roberts
Recommended Follow-up
- Attend: Mastering Platform Threads in Java by Heinz Kabutz
Schedule
The time frames are only estimates and may vary according to how the class is progressing.
Segment 1: Introduction to Java Concurrency (40 minutes—including Q&A)
- What threads are and why we need them
- Benefits and drawbacks of using threads
Break (10 minutes)
Segment 2: Writing Thread-Safe Code (60 minutes)
- Pitfalls of Multithreaded Programming
- Java Memory Model
- Synchronisation
- Designing a Thread-Safe Class
- Encapsulation
- Immutability
Break (10 minutes)
Segment 3: Tasks and Task Execution (50 minutes--including Q&A)
- Thread Pools
- The Executor Framework
- The fork-join framework and parallel streams
Break (10 minutes)
Segment 4: Concurrent Utilities (40 minutes--including Q&A)
- ConcurrentHashMap
- Blocking Queues
- Other concurrent utilities
Break (10 minutes)
Segment 5: Virtual Threads (15 minutes-- including Q&A)
- Basics of Virtual Threads
- Virtual Threads vs. Reactive Programming
- Structured Concurrency
Course wrap-up and next steps (5 minutes)
Your Instructor
Maurice Naftalin
Maurice Naftalin is the co-author of Java Generics and Collections (2nd edition in preparation) and author of Mastering Lambdas. He has been programming and teaching programmers for nearly five decades, half of that time in Java.