
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.
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.
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.
A program that adds up five payments spends almost all of its run time waiting for a bank, while most of the laptop's cores do nothing. You will work out how long sequential code takes, and how long the same jobs could take with more than one thread.
One small program runs twice and prints two different process IDs but the same thread name, and a second program lists every thread the JVM is running. You will explain what a process and a thread each own, what threads share, and why that sharing is both useful and risky.
A laptop with ten cores is running thousands of threads, which raises the question of what running at the same time really means. You will tell CPU-bound work from I/O-bound work, and say whether a slow program needs concurrency or parallelism.
Three lines with Thread.sleep refuse to compile, and then a program that compiles, runs and prints the right answer has a fault of another kind. You will handle InterruptedException in both legal ways and name the two costs that come with every thread.
The station program from the previous section finishes in a third of the time after a change of three lines, and its output arrives in an order nobody wrote. You will create a thread from a Runnable or a lambda, start it, and explain the difference between Thread and Runnable.
Two threads made by extending Thread compile and run correctly, yet a reviewer would comment on line one for a reason that is not about threads. You will choose between extending Thread and implementing Runnable, write a short task as a lambda, and name threads with Thread.ofPlatform.
Three named threads sell nine tickets, every run prints them in a different order, and the summary line reports zero tickets before any is sold. You will check a threaded program by what stays true on every run, and say when the JVM exits and what a daemon thread changes.
After a change of three words the ticket counter prints every line in order with a correct total, and it is broken in a way no compiler or exception reports. You will explain the difference between start and run, and find this bug from three signs in a program's output.
One thread is followed through a working day while main asks for its state at four moments, and you predict each answer before the run. You will name the states a Java thread moves through, read one with getState, and say what to do when finished work must run again.
Three joins put the day's summary after the last ticket, and the counter still reports fewer tickets than were sold. You will say which thread waits in a join, use join with a time limit, tell WAITING from TIMED_WAITING, and say the one thing that a join makes certain.
Moving three lines gives the counter ordered output and a correct total, and makes the program worse. You will spot a join in the wrong place from the clock, state three facts about Thread.sleep, and ask a thread to stop with interrupt, the way Java 27 expects.
Ten threads each add to one shared counter 100,000 times, and four runs give four different totals, all far below a million, with no error. You will point to the exact place where a count is lost, show it in bytecode with javap, and name three symptoms of a race condition.
The lost ticket is slowed down until you can watch two threads read the same value and write the same result on every run. You will close that gap with synchronized, say what atomic means, and measure what the lock costs in run time.
The same keyword sits in two places in one file: one version counts a million tickets correctly, and the other loses most of them. You will name the object behind each of the three forms of synchronized, and write the lock-object form that keeps other code away from your lock.
Four fixes that look right are run one by one against the million-ticket counter, and one of them even moves the total closer to a million. You will say what volatile gives you and what it does not, reject a lock that protects nothing before you run it, and spot a BLOCKED thread.
A four-line program calls wait on a plain object and stops with IllegalMonitorStateException: current thread is not owner. You will say what that message means, what a monitor is, and the rule for when wait, notify and notifyAll may be called.
A program takes a lock, calls wait, then prints nothing and never returns, and a stopwatch then compares sleep and wait inside the same lock. You will explain the two differences between sleep and wait, and tell a BLOCKED thread from a WAITING one.
One thread checks an empty tray in a loop, again and again, to collect a single slip, and you guess what that costs before it is measured. You will write a producer and a consumer with the five-step pattern of synchronized, while, wait, act and notifyAll, and verify the output.
The working producer and consumer is broken twice on purpose: one changed word kills a thread with an exception, and another stops the whole program with no error at all. You will give three reasons why wait belongs in a while loop, and explain how notify can lose a wakeup.
Two threads each take one lock and then want the other's, and the program prints three lines and never returns. You will define a deadlock in one sentence, tell it from a queue behind a slow lock holder, and say why no compiler or exception will ever report it.
A hung program gives a thread dump of 166 lines, and one line in it seems to contradict another. You will find the process with jps, take the dump with jstack or jcmd, and read which lock each thread holds, which lock it wants, and the source line where it is stuck.
A file with a deadlock in it passes two hundred consecutive runs, and then one added log line changes the result. You will explain why passing tests do not prove a deadlock is absent, detect one from code with ThreadMXBean, and remove it with one agreed lock order.
Two threads give back a lock when they cannot get a second one, so the program never hangs, and in this run it also sells no ticket. You will name the four conditions a deadlock needs, use tryLock with a time limit, release the lock in finally, and tell a livelock from a deadlock.
A loop that starts one thread per passenger stops with an OutOfMemoryError before it reaches five thousand threads. You will hand the same work to an ExecutorService with execute, and say where tasks go while every pool thread is busy and what that costs.
A program of three statements creates a pool, runs one task and prints that main is finished, and then the prompt never comes back. You will find the thread that is still waiting in a jstack thread dump, end the program with one line, and read how a closed pool answers new work, field by field.
A program hands one task to a pool, prints one line, and then stops on a line that holds nothing but a closing brace. You will wait for a pool with awaitTermination and a time limit, close it with try-with-resources, and stop it early with shutdownNow, knowing what each call does not do.
A pool from newCachedThreadPool receives five thousand one-second tasks, the same load that stopped one thread per task at the start of this section. You will compare newFixedThreadPool, newCachedThreadPool and newSingleThreadExecutor, read a factory method's source, and choose one on purpose.
Two hundred tasks that each wait a tenth of a second take over five seconds on a pool of four, and about a tenth of a second with a thread each. You will choose a pool size for tasks that compute and for tasks that wait, and say why the number of cores is not always the right size.
A task throws inside a pool: with execute the stack trace prints, and with submit nothing prints and the exit code is zero. You will keep the Future that submit returns, call get on it, and read the task's own exception with getCause.
Two Runnable tasks do not compile: one tries to return a value, and the other calls Thread.sleep with no try and catch. You will write a task that returns a typed result through a Future, submit two lookups, and place get so that one slow lookup does not delay the other.
A program calls get on a Future whose task sleeps for an hour, prints that it is waiting, and never returns to the prompt. You will find where main waits in a jstack thread dump, give get a time limit, and cancel a task whose answer nobody needs.
Ten threads sell a million tickets with no synchronized and no lock, and the total is correct on every run. You will explain why that program cannot lose a ticket, collect every result with invokeAll, and take the first successful one with invokeAny.
A program cancels a Future a tenth of a second into a one-second task, then prints what the Future says and what the thread that runs the task reports. You will read a Future without waiting, with state, resultNow and exceptionNow, and write a task that stops when it is cancelled.
Ten threads write bookings into one HashMap, and in about one run in a hundred every Future comes back with a ClassCastException from a file with no cast. You will name three ways a shared HashMap fails under threads, trace that exception into HashMap's own source, and make the one-word fix.
One thread writes fares into a HashMap while another only reads them, and the reader is the one that fails, with a ConcurrentModificationException. You will say what a fail-fast iterator really checks, and choose between Collections.synchronizedMap, ConcurrentHashMap and CopyOnWriteArrayList.
Ten threads count bookings in a ConcurrentHashMap with getOrDefault followed by put, and the total is wrong by a different amount on every run. You will find the gap between two thread-safe calls, and close it with one call: merge, computeIfAbsent or putIfAbsent.
A counter shared by ten threads reaches exactly one million with no lock anywhere in the file. You will read the compareAndSet retry loop that AtomicInteger runs for you, measure it against synchronized on the same counter, and know where LongAdder fits.
A producer thread and a consumer thread pass slips through an ArrayBlockingQueue, and each waits at the right moment in a file that never calls wait or notify. You will open the queue's own source to see how it does that, and choose between add, offer and put, and between remove, poll and take.
A thread is interrupted before it asks for a ReentrantLock, and the stack trace reports a different exception with no cause. You will put the lock call in the right place for try and finally, read a jstack dump of two threads stuck on ReentrantLocks, and see what ConcurrentHashMap does with null.
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
One thread becomes several. Start threads with Thread and Runnable, explain start versus run, and control them with sleep, join and interrupt.
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.
Java's own tools. Run work on ExecutorService thread pools, collect results with Callable and Future, and share data with ConcurrentHashMap, AtomicInteger and BlockingQueue.
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.