Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Green threads and Native threads in java [duplicate]

Tags:

  • What is the difference between green and native threads?
  • Why does it named as green and native?

I'm new to programming world. I love to learn java. while going through the java threads interview questions, i found this. I have heard about thread, but not these green and native. I goggled about green and native threads, but couldn't get an clear idea.

In which case, the thread is said to be green or native?(i mean in programming)

like image 954
Rachel Avatar asked Mar 07 '13 09:03

Rachel


People also ask

Are Java threads green threads?

Unfortunately, Java does not have built-in support for green threads. Very early versions used green threads instead of native threads as the standard threading model. This changed in Java 1.2, and there has not been any support for it at the JVM level since.

What is green thread model?

Green Thread model Green Thread Model. In this model, threads are completely managed by JVM without any kind of underlying OS support. These threads are implemented at the application level and managed in user space. They are also called cooperative (user-level) threads. Only one green thread can be processed at a time ...

Can two threads run at the same time in Java?

Overview. Multi-thread programming allows us to run threads concurrently, and each thread can handle different tasks. Thus, it makes optimal use of the resources, particularly when our computer has a multiple multi-core CPU or multiple CPUs.

What are the two types of threads in Java?

Java offers two types of threads: user threads and daemon threads. User threads are high-priority threads. The JVM will wait for any user thread to complete its task before terminating it.


1 Answers

What is the difference between green and native threads?

Green threads are scheduled by a virtual machine.

Native threads are scheduled by a operational system.

Why does it named as green and native?

"Green" is earlier JVM threads project code-name. It is name of library, which provided VM-sheduled threads in Java 1.1

Native threads called so because they're belong to native platform.

How do we know that created thread is native or green?

Green threads are in past, JVMs work only with native threads since 1.3

"Green threads" refers to a model in which the Java virtual machine itself creates, manages, and context switches all Java threads within one operating system process. No operating system threads library is used.

"Native threads" refers to a in which the Java virtual machine creates and manages Java threads using the operating system threads library - named libthread on UnixWare - and each Java thread is mapped to one threads library thread.

like image 71
bsiamionau Avatar answered Sep 24 '22 13:09

bsiamionau