Skip to main content

Practice ยท 3 of 3

Virtual threads under load

1. static int vtFanout(int tasks) โ€” run tasks virtual threads via newVirtualThreadPerTaskExecutor, each sleeping 20ms then adding 1 to an AtomicInteger; return the final count. Must work for 10,000 tasks (a platform pool of equal size would blow the 30s sandbox ceiling โ€” VTs make it trivial). 2. static boolean isVirtualInside() โ€” start a virtual thread that records Thread.currentThread().isVirtual() and return that record. 3. static int platformParallelism() โ€” return Runtime.getRuntime().availableProcessors() (the honest CPU-bound ceiling). 4. static boolean virtualThreadsHelpCpuBound() โ€” return false (VTs help waiting, not computing).

Difficulty: advanced

Back to lesson: Practice: Executor & VT drills