The Artima Developer Community
Sponsored Link

Java Answers Forum
Threading and JVM

5 replies on 1 page. Most recent reply: Nov 14, 2002 9:36 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Roshan

Posts: 3
Nickname: jrosh
Registered: May, 2002

Threading and JVM Posted: May 3, 2002 11:49 AM
Reply to this message Reply
Advertisement
hi,
As I understand the underlying oprating system is resposnsible for handling and executing java Threads. My question is, since the Bye code instructions are only understood by the Java VM, how can the OS deal with them (the byte code instructions). Does the OS have a seperate instance of VM for every thread that is invoked.


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Threading and JVM Posted: May 3, 2002 3:33 PM
Reply to this message Reply
First of all the monthly magazine Dr Dobbs Journal (http://www.ddj.com) has a very interesting note on Threading (this month).

Not at all,
You question let me think you do not really see the difference between Threads & Processes.
Back to your question :
It's not technically required that the VM spawns (? dunno if that's proper english ?) a new thread in the underlying OS for each thread you create in the (java) app !
You therefore have the difference between green threads (which are native threads) & emulated threads which are only at VM level but for which there is not thread created in the underlying OS !
Hence for VM using the green threads model, you have the VM creating a thread for each thread ccreated at application level. In each of these threads a Byte code will be transalate into Machine code !

Hope this gives you a lead to further understand ... (?)

Rgds,

Thomas SMETS,
SCJP2 - Brussels

Dirk Froehner

Posts: 2
Nickname: froehner
Registered: Nov, 2002

Re: Threading and JVM Posted: Nov 13, 2002 4:35 AM
Reply to this message Reply
Hi!

Roshan's question is actually not a proof for him not knowing the difference between threads and processes.

Considering e.g. Linux, the default behaviour is that Java spawns a new process for every thread you create in your application. If you look at the output of "ps" then, you see lots of processes instead of just one as you expected and you are very likely to be irritated about how your Java threads are actually implemented on lower levels.

Regards,
Dirk

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Threading and JVM Posted: Nov 13, 2002 3:31 PM
Reply to this message Reply
Dirk,

Are you sure that under Linux it spawns a new process for each Thread ?
I thought the whole point of a good VM was to only spawn threads & definitavely not processes. Sun Solaris has also implemented a Light Weight thingie (i don't remember if it's process or thread, now), as advised in the Unix98 standart...

Can you confirm / infirm any ?

Tia,

Thomas,

Dirk Froehner

Posts: 2
Nickname: froehner
Registered: Nov, 2002

Re: Threading and JVM Posted: Nov 14, 2002 4:20 AM
Reply to this message Reply
> Are you sure that under Linux it spawns a new
> process for each Thread ?
Yes, I am. That is the default case. You can see it in the "ps" output. Of course that is actually not what you want since the advantages of threads against processes are lost then. I'm not sure about the reasons, good explanations are hard to find in the forums, maybe one should ask one of the linux kernel developers and / or the JVM developers.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Threading and JVM Posted: Nov 14, 2002 9:36 AM
Reply to this message Reply
I was wondering about this myself when I saw it on Linux. Someone told me it was a deficiency of Linux, or that all threads on Linux are processes. I'm not enough of a Linux buff to know if that is really the case...

Flat View: This topic has 5 replies on 1 page
Topic: Prime Integers Previous Topic   Next Topic Topic: JDBC

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use