Nội dung
Danh sách bài học
- 01~22 phút
Thread cơ bản — chạy song song, start/join/interrupt
Thread và Runnable, lifecycle 6 trạng thái, start vs run, join, interrupt cooperative. Vì sao single-thread không đủ khi gặp I/O, thread sinh ra từ đâu trong JVM, và tại sao Thread.stop() bị deprecated.
- 02~28 phút
synchronized và volatile — memory model và happens-before
Atomicity vs visibility, synchronized là mutex + visibility, volatile chỉ visibility, khái niệm happens-before. Vì sao counter++ không safe dù thêm volatile, và làm cách nào JVM/CPU cache biến khiến thread A không thấy ghi của thread B.
- 03~25 phút
ExecutorService và CompletableFuture — thread pool và async
Vì sao không dùng new Thread() trong production. Thread pool với ExecutorService, 4 factory, Future.get() blocking. CompletableFuture chain async không callback hell, thenApply vs thenCompose, exceptionally.
- 04~22 phút
Concurrent collections — ConcurrentHashMap, CopyOnWrite, BlockingQueue
Vì sao HashMap có thể infinite loop dưới multithread. Lock striping của ConcurrentHashMap, copy-on-write cho read-heavy list, BlockingQueue cho producer-consumer. Back-pressure pattern.
- 05~22 phút
Virtual threads — Java 21 lightweight concurrency
Project Loom, JEP 444 Java 21. Platform thread tốn 1MB, virtual thread ~300 byte. Triệu thread trong 1 JVM. Carrier thread, mount/unmount, pinning. Khi nào dùng, khi nào KHÔNG dùng.
- 06~30 phút
Mini-challenge: Concurrent price aggregator
Bài thực hành khép lại Module 10 — gọi 5 'API' song song với CompletableFuture, timeout, fallback, aggregate kết quả. Mô phỏng backend thực tế.