From: Jack on
If there are several java applications/programs running on the same
machine, are these java applications/programs using their own JVMs or
are they share the same JVM?

Thanks.
From: Knute Johnson on
On 1/24/2010 7:56 PM, Jack wrote:
> If there are several java applications/programs running on the same
> machine, are these java applications/programs using their own JVMs or
> are they share the same JVM?
>
> Thanks.

Each time you start a Java app, you create a new JVM. That's not to say
that you can't have a Java program that loads other Java programs if you
want them run on the same JVM. I don't know what the state of things is
in browsers for sure but I would suspect that every applet that is
loaded gets its own JVM.

--

Knute Johnson
email s/nospam/knute2010/

From: Mike Schilling on
Knute Johnson wrote:
> On 1/24/2010 7:56 PM, Jack wrote:
>> If there are several java applications/programs running on the same
>> machine, are these java applications/programs using their own JVMs
>> or
>> are they share the same JVM?
>>
>> Thanks.
>
> Each time you start a Java app, you create a new JVM. That's not to
> say that you can't have a Java program that loads other Java
> programs
> if you want them run on the same JVM. I don't know what the state
> of
> things is in browsers for sure but I would suspect that every applet
> that is loaded gets its own JVM.

Web servers and application servers, in general, run all of their
applications in a single JVM (or perhaps a replicated set of JVMs,
each of which can run any of their applications.)


From: Thomas Pornin on
According to Jack <junw2000(a)gmail.com>:
> If there are several java applications/programs running on the same
> machine, are these java applications/programs using their own JVMs or
> are they share the same JVM?

It fully depends on what you mean by "JVM".

At the source code level, two applications or applets are deemed
distinct if they "do not see each other": the classes defined in one
application are not visible from the other, and both applications may
have identically-named classes. Since Java applications are isolated
from system and hardware, that lack of visibility is all that makes
sense from the application point of view.

From the outside, things are more complex. Let's assume for now that the
JVM is launched as the 'java.exe' (Windows) or '/usr/bin/java' (typical
Linux) executable. Then the application runs in its own JVM instance,
i.e. a single process with its address space, separated from the other
processes by way of the operating system facilities. Still, the
executable code comes from files, which are not duplicated (you may run
several applications from the same executable), and the in-memory copy
of executable code may be shared between several concurrently invoked
Java application. This happens under the hood, and is invisible to
applications, except that sharing saves memory and thus improves
performance. On that subject, it is worth noticing that a Java
application involves a rather small chunk of pre-compiled native code,
and a bulk of dynamically translated bytecode; the in-memory sharing of
executable code by the OS can be performed only on the native code.

Another possibility is integrating the JVM in a bigger application, and
calling it through JNI. This involves calling JNI_CreateJavaVM(). There,
several Java VM "instances" may coexist within the same address space.
They still do not see each other, as if they were in separate processes,
but from the OS point of view they are a unique process. The native code
is shared in RAM.


--Thomas Pornin
From: Arne Vajhøj on
On 25-01-2010 01:17, Mike Schilling wrote:
> Knute Johnson wrote:
>> On 1/24/2010 7:56 PM, Jack wrote:
>>> If there are several java applications/programs running on the same
>>> machine, are these java applications/programs using their own JVMs
>>> or
>>> are they share the same JVM?
>>
>> Each time you start a Java app, you create a new JVM. That's not to
>> say that you can't have a Java program that loads other Java
>> programs
>> if you want them run on the same JVM. I don't know what the state
>> of
>> things is in browsers for sure but I would suspect that every applet
>> that is loaded gets its own JVM.
>
> Web servers and application servers, in general, run all of their
> applications in a single JVM (or perhaps a replicated set of JVMs,
> each of which can run any of their applications.)

Java EE has a different application concept than Java SE.

Seen from Java SE perspective the app server is the app
and the ear's are plugins.

Seen from Java EE perspective the ear's are multiple apps.

Arne