What are Difference between Green Threads and non-green/native threads in java
Green threads are also known as user-level threads.
Non-Green threads are also known as native threads.
Green threads are user-level threads. They are scheduled by an simple user-level process, not by the kernel.
Non-Green threads are not user-level threads. They are not scheduled by an simple user-level process.
Green threads are implemented at the application level rather than in the OS level.
Non-Green threads are implemented at the OS level rather than the application level.
Green threads are not at all dependent on OS thread scheduler.
Non-Green threads are totally dependent on OS thread scheduler.
Green threads were used till Java 2, usage of Green threads was completely stopped in the java 3.
From Java 3 we are totally using non-Green threads.
In green thread - JVM (java virtual machine) creates, manages, and context switches all threads within one OS (operating system) process. Operating system threads API’s are not used.
Non-green thread uses Operating system threads API’s.
Green Threads cannot take advantage of multi-core processors.
Now, you must be wondering why green threads aren’t able to take advantage of multi-core processors. Answer is -
Because green threads is scheduled to simulate multi-threading environment but actually only green one thread exists, so single thread of course cannot be executed on multiple processors.
Non-Green Threads takes advantage of multi-core processors.
But in case of non-green threads multiple threads are used to create multi-threading environment, so multiple threads can be easily scheduled to take advantage of multi-core processors.
Green threads doesn’t have their own stack and memory is allocated from heap area.
Non-green threads have their own stack.
They are named green thread because - Green was the code name given to project which provided JVM scheduled threads.
Non-green threads are called native threads because they uses platform’s native multi-threading support.
Green threads were generally used when the OS does not provide multi-threading API’s.