Scrivio Interview library

Virtual threads and structured concurrency

25 questions in 8 subtopics.

Virtual threads model

ConceptFoundations6 min read
What is a virtual thread in Java 21+, how do you create one, and how does it differ from a platform thread?
CodingFoundations6 min read
How long does this take to run, roughly, and how would the answer change with
Executors.newFixedThreadPool(200)? try (var ex = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 10_000; i++) ex.submit(() -> {
Thread.sleep(1000);
return null;
});
}
ConceptIntermediate7 min read
What are the memory and observability characteristics of virtual threads that matter in production, and how do you get a thread dump that includes them?

Carrier threads and mounting

InternalsFoundations6 min read
Explain mounting and unmounting: what happens when a virtual thread calls a blocking socket read, and which threads are carriers?
InternalsIntermediate6 min read
How is the virtual thread scheduler configured, and when would you change it?
DebuggingIntermediate6 min read
After moving to virtual threads, a library that used Thread.currentThread().getId() as a key to cache per-thread connections starts creating thousands of connections. Explain.
ConceptPrincipal6 min read
Virtual threads took years of JDK work before becoming final in Java 21, because blocking operations across many APIs had to be changed to unmount, and some pinning remained until JDK 24. What does this cost tell you, and how should you sequence a multi-year adoption?

Pinning and synchronized

ConceptFoundations6 min read
What is pinning for virtual threads, what caused it before JDK 24, and what changed with JEP 491?
DebuggingIntermediate7 min read
On a Java 21 service, enabling virtual threads made throughput collapse under load. A thread dump shows all carrier threads busy, many virtual threads waiting, and frames inside a JDBC driver's synchronized method doing socket reads. Explain and give your options.
ScenarioAdvanced6 min read
Your platform runs on Java 21, and leadership wants to enable virtual threads across 60 services. Would you require an upgrade to Java 25 first? Lay out the trade-offs.

Structured concurrency

CodingFoundations6 min read
Using only final APIs, write code that fetches a user and their orders in parallel on virtual threads and returns both, then explain what goes wrong if the user call fails quickly while the orders call is slow.
ConceptIntermediate7 min read
What problem does structured concurrency (StructuredTaskScope) solve compared with submitting tasks to an ExecutorService, and what is its status in Java 25?
LeadershipAdvanced6 min read
A team wants to use StructuredTaskScope in production services on Java 25 with --enable-preview because it simplifies fan-out code. What is your decision and what conditions would you set?

Scoped values

ConceptIntermediate6 min read
What are scoped values (ScopedValue, final in Java 25), and how do they differ from ThreadLocal?
DesignAdvanced7 min read
Your shared security library stores the authenticated principal in a ThreadLocal used by 50 services. Propose a migration path to ScopedValue and state its limitations.

Virtual threads with Spring Boot

ConceptFoundations6 min read
How do you enable virtual threads in Spring Boot, and what does the setting change?
DebuggingIntermediate6 min read
A Spring Boot application with virtual threads enabled uses @Scheduled tasks only and has no web server. It starts and then exits immediately. Explain and fix.
ScenarioIntermediate6 min read
After enabling spring.threads.virtual.enabled, a service sees many HikariCP connection timeout errors under the same traffic that worked before. Explain why and what you would change.
LeadershipPrincipal7 min read
You have 200 Spring Boot services on Java 17, some on Boot 2 and some on Boot 3. Plan the sequencing for adopting virtual threads over two years, including prerequisites and risks.

When virtual threads do not help

ConceptFoundations6 min read
In which cases do virtual threads not improve performance, and why?
ScenarioIntermediate6 min read
A team enabled virtual threads in an image-resizing service and saw no change in throughput, while CPU stays at 100%. Another team pooled virtual threads in a fixed pool of 50 and saw no gain either. Explain both.

Virtual threads vs reactive

ConceptIntermediate6 min read
Compare virtual threads with reactive programming (for example Project Reactor and WebFlux) for a typical request-response service.
LeadershipAdvanced6 min read
You own 30 WebFlux services written over five years. Some engineers want to move them back to Spring MVC on virtual threads. How would you decide which, if any, to migrate?
ConceptPrincipal7 min read
Java chose user-mode threads (Project Loom) rather than async/await keywords as C# and JavaScript did. Why, and what does that imply for language and framework bets in your organisation?
LeadershipPrincipal6 min read
As the technical leader of a large Java organisation in the virtual-thread era, what would you standardise or forbid to avoid the mistakes of the thread-pool era?