Virtual Threads (Project Loom)
Design a small subsystem that relies on Virtual Threads (Project Loom). Outline components, data flow, failure modes, and metrics.
Answers use simple, clear English.
Quick interview answer
Use Virtual Threads (Project Loom) as the core idea. Example shape: HTTP gateway handles 10k concurrent upstream calls each on its own virtual thread..
Detailed answer
Use Virtual Threads (Project Loom) as the core idea. Example shape: HTTP gateway handles 10k concurrent upstream calls each on its own virtual thread.. Watch for: Pinning with synchronized/native/JDBC drivers still possible; not for CPU-bound.. Measure success via latency/error/saturation. Core: Virtual threads are lightweight; block on IO without pinning platform thread (mostly). Executors.newVirtualThreadPerTaskExecutor() simplifies massive concurrency. Real-time example: HTTP gateway handles 10k concurrent upstream calls each on its own virtual thread. Pros: Simpler than reactive stacks for IO-bound code; familiar thread model. Cons: Pinning with synchronized/native/JDBC drivers still possible; not for CPU-bound. Common mistakes: Using platform thread pool sizes tuned for virtual threads; thread-local abuse. Best practices: Use structured concurrency; prefer ReentrantLock over synchronized in hot paths. Audience level: Senior.
Full explanation
Virtual threads are lightweight; block on IO without pinning platform thread (mostly). Executors.newVirtualThreadPerTaskExecutor() simplifies massive concurrency.
Real example & use case
HTTP gateway handles 10k concurrent upstream calls each on its own virtual thread.
Pros & cons
Pros: Simpler than reactive stacks for IO-bound code; familiar thread model. Cons: Pinning with synchronized/native/JDBC drivers still possible; not for CPU-bound.
Common mistakes
Using platform thread pool sizes tuned for virtual threads; thread-local abuse.
Best practices
Use structured concurrency; prefer ReentrantLock over synchronized in hot paths.
Follow-up questions
Only answered follow-ups are shown — click to open with full answers