Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM & Java Threads Scheduling

 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have read a article that when it comes to multi processor systems , we can't get the advantage of running multiple threads simultaneously since every threads are in a single JVM process. Indeed when I go further, I got to know that some JVM implementations are built to map Java thread to OS level native threads.

My question is this, by default I used sun's JVM 1.6 implementations which is widely spread among Java newbies.So
Q1.How does this modern JVM handle thread scheduling ?
Q2.Does it handle JVM itself or map Java threads to native threads ?
Q3.So what will happens to platform independence when operating system handles thread scheduling?

Please somebody give me clear answer.

Thanks & Regards,
Nuwan Arambage



 
Stephan van Hulst
Bartender
Pie
Posts: 5590
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no default behaviour. It depends on the platform the JVM runs on. Java will usually use native threads, but on some operating systems it uses so called "green threads", which the JVM handles itself and is executed by a single native thread.

You shouldn't have to worry about this. It is all handled by the JVM, and is invisible to the programmer. The only real difference I can think of is that on an implementation that uses green threads, there will be no performance gain from multi-threaded divide-and-conquer algorithms. However, the same lack of performance gain is true for implementations that use native threads, but run on a machine with a single core.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephan,
In nutshell, what do you mean by it depends on the platform ?. is it related to NT or Linux ?
 
Henry Wong
author
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:There is no default behaviour. It depends on the platform the JVM runs on. Java will usually use native threads, but on some operating systems it uses so called "green threads", which the JVM handles itself and is executed by a single native thread.



To provide a bit more context, there hasn't been a "green threads" implementation in over 10 years. I believe all modern JVMs uses the native threading implementation; and I believe that all modern OSes do allow an application threads to use any (and even all) of the processors on a single machine.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nuwan Arambage wrote:Hi Stephan,
In nutshell, what do you mean by it depends on the platform ?. is it related to NT or Linux ?


"depends on the platform" means exactly that. Threading behavior is handled by the operating system, hence, its behavior is dependent on the system hardware/OS/configuration that the JVM is running on.

Henry
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, the only OS where you still have choices is the Solaris OS. I believe Java 1.1 was all Java-controlled threads, but since Java 1.2 and above, it went to native threads. In Solaris you can control the behavior (or at least as recent as Java 5 you could).

So for Q1: Thread scheduling is almost exclusively handled by the OS
Q2: For most OS, threads are native but for Solaris there is some control over this
Q3: You don't have to worry about platform independence - the code will be independent. On Solaris you can tweak the performance using command line options when launching Java
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for everyone's contribution to make everything clear to the deepest..



 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excuse me people,

I don't know whether I digest 'Platform Independence' buzz word correctly.You all have already told that threads are mostly depends on the operating system where java virtual machine runs.So java threading mechanism depends on underlying operating system configuration. In fact, I feel java's platform independence is deviated.

Could someone clarify what I was thinking seems real or hypothetical....

thanks...

Nuwan Arambage

 
Stephan van Hulst
Bartender
Pie
Posts: 5590
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM itself and its internals (including the threading mechanism) are always dependent on the underlying operating system. However, the JVM hides all this stuff from the programmer. The language and the API provided by the JVM is platform independent. You can always use these the same way, regardless of the underlying mechanisms.

It's the same with Threads. The JVM may use platform dependent mechanisms to implement Threads, but these are invisible to you, and you don't have to worry about them. You always interact with Threads in the same manner, regardless of the machine you are working on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic