Java.Multithreading.What are “green threads” and do they exist in Java?

🌱 What Are Green Threads?

Green threads are threads that are scheduled and managed entirely by the JVM (or user-level runtime), not the OS.

That means:

  • The JVM simulates threading using only one OS thread (or very few)
  • Thread switching is handled inside the JVM, not by the OS
  • Good for platforms where OS threads are expensive or unavailable

🧠 Think of green threads as “user-mode” threads.


💡 Characteristics of Green Threads

FeatureGreen Threads
Scheduled byJVM or runtime (user-space)
Number of OS threadsUsually just 1
PortabilityHigh (doesn’t depend on OS threading)
True parallelism❌ No (on multi-core systems)
Performance on IO✅ Often faster for lightweight tasks
Blocking behavior❌ One thread blocks = all block

☕ Did Java Ever Use Green Threads?

Yes! Java originally used green threads, especially in:

  • Early JVMs (like on Solaris or old Linux systems)
  • Java 1.1 and some embedded environments

But…


❌ Do Green Threads Exist in Java Today?

🔥 No — modern Java uses native OS threads by default.

Since Java 1.2, the HotSpot JVM uses native threads, where:

  • Each Java thread = a real OS thread
  • The OS scheduler manages them
  • You get true parallelism on multi-core CPUs

This makes Java apps faster and more scalable on modern machines.

🚀 But Wait — Green Threads Are Coming Back?

Yes! In the form of:

🧵 Project Loom (since Java 19+ as preview)

Loom introduces virtual threads, which are kind of like modern green threads.

  • Scheduled by JVM, not OS
  • Thousands of threads with tiny memory footprint
  • Work cooperatively unless they block on native code
  • Enable massive concurrency (millions of threads!)
Thread.startVirtualThread(() -> {
    System.out.println("Hello from a virtual thread!");
});

✅ These are green threads, reborn — and they’re amazing for lightweight, IO-heavy applications like web servers.


🧠 Summary Table

FeatureGreen ThreadsNative ThreadsVirtual Threads (Loom)
Managed byJVMOSJVM
Introduced in JavaJava 1.0–1.1Java 1.2+Java 19+ (preview)
True parallelism❌ No✅ Yes✅ Yes (cooperatively)
Memory overhead🟢 Very low🔴 Higher🟢 Very low
Blocking behavior❌ Blocks all✅ Thread-local blocking🟢 Handles well with Loom
This entry was posted in Без рубрики. Bookmark the permalink.