Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Java Multithreading & Concurrency: Virtual Threads, Java 27
New
Rating: 2.5 out of 5(1 rating)
7 students

Java Multithreading & Concurrency: Virtual Threads, Java 27

Java concurrency from the first thread to structured concurrency: race conditions, deadlock, thread pools, 250+ programs
Last updated 10/2026
English

What you'll learn

  • Explain why ten threads lose most of a million updates to one shared counter with no error, show the race condition with javap, and fix it with synchronized
  • Read a jstack thread dump of a hung program: which thread holds which lock, and on which line. Then make the deadlock impossible with one lock order
  • Run tasks on an ExecutorService thread pool: choose fixed or cached, size it for work that waits or computes, and shut it down so the JVM exits
  • Start a million virtual threads, explain carrier threads and pinning, and limit calls to a slow service with a Semaphore instead of a pool
  • Use structured concurrency: group subtasks in a StructuredTaskScope so they succeed or fail together under one deadline, and share a value with ScopedValue
  • Create threads with Thread and Runnable, explain start versus run, wait for threads to finish with join, and ask a thread to stop with interrupt
  • Write a producer and a consumer with wait and notifyAll, and explain why wait belongs in a while loop inside synchronized
  • Return results with Callable and Future: put a timeout on get, cancel a task, read the real failure with getCause, and use invokeAll or invokeAny
  • Replace a HashMap that loses entries under threads with ConcurrentHashMap, close a get-then-put gap with merge, and count with AtomicInteger or LongAdder
  • Say what volatile guarantees and what it does not, and use ReentrantLock with tryLock and a timeout so that a thread gives up instead of hanging
  • Explain why a synchronized block that held up virtual threads on Java 21 no longer does on Java 27, using one file measured on Java 21, 25 and 27

Course content

12 sections • 54 lectures • 10h 10m total length
  • Why Learn Java Concurrency, and Why Now: Races, Deadlock, Virtual Threads5:23

    Ten threads sell a million tickets and the counter shows far fewer, a second program stops and never continues, and a third exits with its work never done. You will know the three ways threaded code fails, why advice written for an older Java can mislead, and which skill you need most.

  • What This Course Is About: Course Map and Prerequisites5:52

    A route map of the whole course is drawn on screen, from the first thread to structured concurrency and scoped values, with the format that every lecture follows. You will know where each topic is taught, which Java basics you need before you start, and what the course leaves out.

  • How to Get the Most from This Course: JDK 27 and the GitHub Code6:19

    One of the course programs refuses to run on the instructor's own machine, and you guess the cause before a one-line check finds it. You will have the course code from GitHub, a JDK 27 that runs each file with java and the file name, and one study habit to use before every run.

Requirements

  • Java basics: classes and objects, methods, interfaces, exceptions with try and catch, and generic types such as a List of String
  • No threading knowledge is needed. Lambdas, records and try-with-resources are explained when they first appear
  • JDK 27: the first line of java -version must say 27. JDK 21 refuses most of the programs as written. Structured concurrency programs need --enable-preview
  • No IDE and no build tool. Each program is one source file that you run in a terminal with java and the file name. Any text editor works
  • A few gigabytes of free memory. Several lectures start a million threads, and the heaviest run peaked at about 2.4 GB on the instructor's 16 GB Mac

Description

This course contains the use of artificial intelligence.

Ten threads each add one to a shared counter 100,000 times, the program prints 136,405 instead of 1,000,000, and nothing reports an error. This Java multithreading course explains that result and others like it, from your first thread to virtual threads and structured concurrency on Java 27, with more than 250 small programs to try yourself.

A bug in threaded code often looks like that one: every line ran as written, and the answer is wrong. Another program in the course contains a deadlock and still passed 200 runs in a row, so tests alone do not find these bugs. If you can start a thread but cannot say why that total is wrong, or you watched thread tutorials and remembered little, this Java concurrency course was written for you.

The route, in four steps

  1. One thread becomes several. Start threads with Thread and Runnable, explain start versus run, and control them with sleep, join and interrupt.

  2. What goes wrong when threads share. Fix a race condition with synchronized, coordinate threads with wait and notifyAll, read a deadlock in a jstack thread dump, and prevent it with one lock order.

  3. Java's own tools. Run work on ExecutorService thread pools, collect results with Callable and Future, and share data with ConcurrentHashMap, AtomicInteger and BlockingQueue.

  4. Modern Java. Start a million virtual threads, then group tasks in a StructuredTaskScope so that they succeed or fail together, and share a value with ScopedValue.

How each lecture works

After the short Start Here section, each lecture opens on a real run, often a wrong total, a hang, or a program that exits before its work is done. Before a program runs, you predict the result while a small clock ticks. A wrong guess shows which picture in your head needs fixing. The video is narrated animation, not slides read aloud: code, terminal output and one drawn story, a railway station where every clerk behind a booking window is a thread. Most lectures run ten to twelve minutes.

Is Java 27 too new for your job?

Every program was run on Java 27 and every result was measured for this course, so you need JDK 27 to run the code as written. No IDE or build tool is needed: you start each file with java and the file name. Most of what you learn is far older: Runnable dates from Java 1.0 and Callable from Java 5. Virtual threads have been standard since Java 21, and scoped values are final since Java 25. Structured concurrency is still a preview API in Java 27, so the programs that use it run with the --enable-preview flag and may need edits at the next release. Where advice changed between versions, the course measures it: a thousand virtual threads, each holding a synchronized lock while it sleeps, took 10,364 milliseconds on Java 21 and 112 on Java 27.

What this course does not cover

CompletableFuture is named once and not taught. The course also leaves out CountDownLatch, CyclicBarrier, ReadWriteLock, scheduled executors and the fork/join framework. There are no reactive frameworks, no parallel streams and no Spring, and nothing runs across several machines. You need Java basics, but no threading knowledge.

Check it before you decide

Judge this course by what you can verify. The code is in a public GitHub repository, AnandRochlani/java-multithreading, with the output captured on the instructor's machine. Watch the free preview lectures, predict each run, then run one program and compare your output. Then decide for yourself.

Who this course is for:

  • Java developers who can start a thread but cannot yet say why a shared total comes out wrong, or why a program hangs with no error
  • Developers on Java 17 or 21 who hear about virtual threads and structured concurrency and want to see them run and measured on a current JDK
  • Developers who watched thread tutorials before and remembered little: here you predict what a program will do before it runs
  • Developers preparing for interview questions such as start versus run, sleep versus wait, deadlock, and producer and consumer
  • Students and self-taught programmers who know Java basics and have never written a thread: the course begins before the first one
  • Not for you if you are new to Java, or need CompletableFuture, CountDownLatch, the fork/join framework, parallel streams, reactive frameworks or Spring