threading in JAVA

Hi !My names is Andrea Marini.I want to ask you something about JVM.With a multiprocessor, the JVM is really multithreading ? Thanks,andrea
[181 byte] By [MariniAndreaa] at [2007-11-26 15:09:18]
# 1

> Hi !

> My names is Andrea Marini.

> I want to ask you something about JVM.

> With a multiprocessor, the JVM is really

> multithreading ?

>

> Thanks,

> andrea

What do you understand by multithreading?Define multithreading.

qUesT_foR_knOwLeDgea at 2007-7-8 8:59:51 > top of Java-index,Java Essentials,New To Java...
# 2

> Hi !

> My names is Andrea Marini.

> I want to ask you something about JVM.

> With a multiprocessor, the JVM is really

> multithreading ?

Java's threading model lets you specify that multiple threads can run concurrently. That is, as far as you're concerned, they might actually be executing simultaneously (on 2 different processors, for example), or they might be taking turns, but looking like they're running simultaneously, or one might run to completion before the other one starts. You don't know and you don't care.

If you have a multi-CPU or multi-core box, how the threads get distributed across the CPUs/cores is determined by the VM and the OS. You can't know or control it from your Java code. However, I would imagine that most modern VMs on most multi-CPU systems will allow for true simultaneous execution--different threads running simultaneously on different CPUs. Note, however, the the OS's scheduler still controls who gets CPU time when, and there will be more running than just your Java app.

jverda at 2007-7-8 8:59:51 > top of Java-index,Java Essentials,New To Java...
# 3

> > Hi !

> > My names is Andrea Marini.

> > I want to ask you something about JVM.

> > With a multiprocessor, the JVM is really

> > multithreading ?

> >

> > Thanks,

> > andrea

Firat of all you need to understand that whatever threading priorities the JVM assigns but ultimaltely its the OS that sets the scheduling of the JVM threads along with the other processes running in the OS.So in a multiprocessor environment the threads created by the JVM are given to the OS and its the OS that then schedules it using various algos depending on the system load and perforamance(a lot of other factors are there too) to obtain concurrent execution of threads.

It might also depend incase we have one master processor and other slave processor and the master has been defined to assign one process and all its threads to one slave only.Then it would make make no difference between a uniprocessor and a multiprocessor environment except that there are only the JVM threads running on that assigned processor so that would still make execution faster.It ultimately depends on how the multiprocessor architechture has been defined by the manufacturers

qUesT_foR_knOwLeDgea at 2007-7-8 8:59:51 > top of Java-index,Java Essentials,New To Java...
# 4

If the JVM you are running says it supports "green" threads, then the answer is almost certainly "no". "Green" threads are run "inside of" the JVM process - the root OS does NOT see multiple threads of execution.

If the JVM you are using says it supports "native" threads, then there is at least the chance that your multithreaded app will run on more than one CPU at a time. most modern JVMs use native threading.

Under some OS's, you need to explicitly tell the JVM how many CPUs it's allowed to take up. At this level, you generaly either take the JVM default, or you find yourself writing JNI to talk to the OS at startup.

Grant

ggaineya at 2007-7-8 8:59:51 > top of Java-index,Java Essentials,New To Java...
# 5
Are there still green thread JVMs around?
jverda at 2007-7-8 8:59:51 > top of Java-index,Java Essentials,New To Java...
# 6

> Are there still green thread JVMs around?

Possibly - if only because there are still people using old JVMs. And I wouldn't be surprised to find green-thread JVMs on platforms other than the Big Three (Windows, Solaris, Mac).

I only offered it up as a possible answer, because "is it really multithreading" is often a poorly-worded way of asking if the JVM is using native threads.

G

ggaineya at 2007-7-8 8:59:51 > top of Java-index,Java Essentials,New To Java...
# 7
Green Thread JVM's?But thats obsolete,isn't it?That will make the VM just crappy then.
qUesT_foR_knOwLeDgea at 2007-7-8 8:59:51 > top of Java-index,Java Essentials,New To Java...