Level 1 · Apprentice0 XP
Two ways to wait for slow things without wasting threads.
Step 1 / 5
ProblemA server has a pool of 200 threads. Each request calls a slow database and a slow API, and its thread just waits. With 200 requests in flight the pool is empty and the 201st user waits, while the CPU is almost idle.
← → step
Before this: Threads and shared state
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Simulate two slow calls with Thread.sleep (400 ms and 900 ms). Run them one after the other and time it. Then run them together with CompletableFuture and thenCombine, and again with a virtual-thread executor. Compare the three times.