NhacVibe
Ảnh bìa Java : Concurrency

Java : Concurrency

Oddly Yogi · 7 lượt xem · 13 thg 11, 2026

Mô tả

A library app has to send hundreds of reminders, and each one waits on a slow mail server. In this video we make the Shelf library app do many things at once with Java's concurrency tools. Like clerks at a post office sharing one tally board, threads that update the same data at the same time lose updates, and we see a real race condition happen. We fix it with synchronized, AtomicInteger and ConcurrentHashMap, run work on an ExecutorService with Future and invokeAll, chain steps with CompletableFuture, and then run ten thousand blocking tasks on virtual threads. We send Shelf's overdue reminders concurrently, limited with a Semaphore, and finish with two newer tools: structured concurrency, a preview feature in Java 25 that cancels sibling tasks when one fails, and scoped values, final in Java 25.

Versions: Java 25 LTS (Eclipse Temurin 25.0.5), Apache Maven 3.10.0, JUnit 6.1.3, Mockito 5.24.0.

In this chapter:
00:00 Clerks and one tally board
01:34 Starting threads
02:59 Names, states and interruption
04:21 Fixing the race
06:21 Concurrent maps and thread builders
07:46 Thread pools and futures
09:50 Chaining with CompletableFuture
11:46 Virtual threads
14:03 Concurrent reminders in Shelf
17:01 Structured concurrency
19:21 Scoped values
20:33 Wrap up

This is Chapter 13 of 15 in the "Java" series.
#Java #Java25 #Concurrency #VirtualThreads #LearnJava