concurrency
Thread t = Thread.startVirtualThread(() -> {
System.out.println("virtual");
});
t.join();
Platform threads
A platform thread maps to an OS thread Creating thousands of them is expensive That is why the old advice says do not spawn a thread per request
Virtual threads
Virtual threads are lightweight They run on a small pool of platform threads Use them for blocking I/O workloads They do not make CPU bound work faster
Sharing state
volatile gives visibility
synchronized gives mutual exclusion
ConcurrentHashMap gives thread safe maps without locking the whole map
Do not synchronise everything Locking is a design, not a reflex
What to remember
Concurrency is about progress Parallelism is about speed A web server needs the first A video encoder needs the second
Next
Records in 10 records
Posted