Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Grren Thread/User Thread..!

 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I belive green thread are the threads that are created and managed by the JVM and it cannot take advantage of multiple process as its runs within single process that JVM is in. Actually JVM will exist in one of the native threads created by OS.

Well when we say java and some class file name on command prompt Is there some thread like green thread created by JVM that keeps listening for java executable files and as soon as we run the java file is it attached to that thread. Does JVM create thread for each java program that we run?

One more query is like what if we actually write a thread class?
I belive in this thread gets attached to the JVM created thread but the control is with the user as its user created? Am i Right?

Also then in this case will there be 2 stacks?? one for the thread from JVM and other from the User thread?

I would also like to know that can we install multiple JVM on Same OS say in different drives? and if we can then i belive we will have to use IPC or RMI to communicate as both JVM will be in different process?
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I belive green thread are the threads that are created and managed by the JVM and it cannot take advantage of multiple process as its runs within single process that JVM is in. Actually JVM will exist in one of the native threads created by OS.


Green threads is a threading library that Java used many many years ago. I believe Java stopped using the green threads library, and switched to native threads, at either Java 1.1 or 1.2, don't remember.

With green threads, the OS doesn't see the threads. All context switching and other thread related stuff is implemented in the library. In modern JVMs, Java passes responsibility of threading to the underlying OS.

One more query is like what if we actually write a thread class?
I belive in this thread gets attached to the JVM created thread but the control is with the user as its user created? Am i Right?

Also then in this case will there be 2 stacks?? one for the thread from JVM and other from the User thread?


With modern JVMs, it is the OS that determines when a thread runs, and for how long. With old JVMs, that uses green threads, it is the threading library that does this (within the timeslice allocated to the JVM process). The user can set the priority which can affect the schedulling, but doesn't have absolute control.

Each thread in the process has it's own call stack.

I would also like to know that can we install multiple JVM on Same OS say in different drives? and if we can then i belive we will have to use IPC or RMI to communicate as both JVM will be in different process?


Yes, you can install and run multiple JVMs. They are separate processes if you run them at the same time. And yes, you can use RMI as a communication protocol.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic