Difference between Green Threads and non-green/native threads in java







What are Difference between Green Threads and non-green/native threads in java




Green threads
Non-green/Native threads
1
Green threads are also known as user-level threads.
Non-Green threads are also known as native threads.
2
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.
3
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.
4
Green threads are not at all dependent on OS thread scheduler.
Non-Green threads are totally dependent on OS thread scheduler.
5
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.
6
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.
7
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.
8
Green threads doesn’t have their own stack and memory is allocated from heap area.
Non-green threads have their own stack.
9
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.
10
Green threads were generally used when the OS does not provide multi-threading API’s.
-

No comments:

Post a Comment