Sobes.tech
Junior — Middle

What is the difference in memory volume required between a regular thread and a virtual thread?

sobes.tech AI

Answer from AI

Regular (platform) threads in Java require significant memory resources, as each creates a separate stack (usually several hundred kilobytes) and system resources of the OS to manage the thread.

Virtual threads (introduced in Project Loom) are much lighter in memory consumption, as they are implemented at the JVM level and do not require allocating a separate OS system thread and a large stack. Instead, virtual threads use a much smaller stack and can switch efficiently within one or more system threads.

Approximately:

  • Regular thread: stack ~512 KB (depends on the platform), plus system resources.
  • Virtual thread: stack can be a few kilobytes, and switching between them is very cheap.

This allows creating thousands and even millions of virtual threads without significant increase in memory consumption, which is impossible with regular threads.

What is the difference in memory volume required… - sobes.tech