Prev Next

Java / Java 21 Virtual Threads Interview questions

Define a carrier thread?

A carrier thread is a platform thread that the JVM scheduler uses to actually execute a virtual thread's code. It "carries" the virtual thread while it is mounted.

Carrier threads come from a dedicated internal pool, sized by default to the number of available processor cores, and are shared across whichever virtual threads currently need to run.

When a mounted virtual thread performs a blocking operation the JVM knows how to handle asynchronously, it is unmounted and its carrier is freed to run a different virtual thread.

A carrier thread is best described as:
By default, the carrier thread pool is sized to:

More Related questions...

What is a virtual thread in Java 21? What is Project Loom? What are the types of threads available in Java 21? How do you create a virtual thread? What is the purpose of virtual threads? What is a platform thread? Define a carrier thread? Describe the Thread.Builder API? What is the purpose of Thread.ofVirtual()? How do you check if a thread is virtual? What is a continuation in the context of virtual threads? List the ways to create virtual threads in Java 21? What is the default naming behavior for virtual threads? How do you use Executors.newVirtualThreadPerTaskExecutor()? What is structured concurrency? What is the difference between virtual threads and platform threads? Why is thread pinning a concern with virtual threads? Why do we use virtual threads instead of traditional thread pools? How does the JVM schedule virtual threads? How is a virtual thread mounted onto a carrier thread? When should you use virtual threads over platform threads? When would you choose platform threads over virtual threads? What happens when a virtual thread performs blocking I/O? Why doesn't ThreadLocal work well with virtual threads? What is a ScopedValue and why was it introduced? How does StructuredTaskScope manage a group of virtual threads? Why should you avoid pooling virtual threads? What is the difference between synchronized blocks and ReentrantLock for pinning? How does virtual thread stack size differ from a platform thread's? What happens when you call Thread.sleep() inside a virtual thread? Why is the number of carrier threads limited by default? What is the difference between ExecutorService and StructuredTaskScope? How does virtual thread creation cost compare to platform threads? Why do virtual thread priorities have little practical effect? How do you configure the number of carrier threads used? Explain the lifecycle of a virtual thread? Explain the execution flow when a virtual thread makes a blocking call? Explain the internal working of the scheduler behind virtual threads? How can you optimize an application to fully benefit from virtual threads? How do you troubleshoot thread pinning caused by synchronized blocks? How do you migrate a thread-pool-based application to virtual threads? How do you monitor and debug virtual threads using JFR? How can you detect thread pinning in a production system? Which is better and why: thread pools or virtual threads for I/O-heavy services? Explain how virtual threads interact with native code and JNI calls? What is the difference between virtual threads and reactive programming? What is the difference between virtual threads and Kotlin coroutines or Go goroutines? Explain the internal working of StructuredTaskScope's shutdown behavior? How does the JVM avoid exhausting memory with millions of virtual threads? Explain the execution flow of a structured concurrency task with subtasks failing?
Show more question and Answers...


Comments & Discussions