sanjay
sanjay

Reputation: 45

Java HeapSpace allocation in same machine

Can anyone explain me, how heap space will allocate if three java applications runs on a same machine.?

Whether each JVM allocates separate heap space.? else it will be common for three applications.?

Thanks in advance.

Upvotes: 1

Views: 170

Answers (4)

TheLostMind
TheLostMind

Reputation: 36304

The OS allocates a certain amount of space to the JVM... It is left to the JVM to allocate that memory to the different threads(I dont want to say processes) under it... U can change the amount of memory to be given to each thread under the JVM, but its not guaranteed to work.. Its the JVM's call finally. Increasing the memory size is just a hint to the JVM - telling it - "bro! this thread needs more memory... Try allocating it."

Upvotes: 0

Raedwald
Raedwald

Reputation: 48682

Each JVM has its own "heap space", in the sense that each JVM has its own virtual address space that it uses for its heap. From the perspective of each JVM, it has its own memory space that only it accesses.

Behind the scenes, however, it its a little bit more complicated. The private memory space of each JVM is an illusion created by the virtual memory system of the operating-system kernel. In practice, all the programs running on the computer must share the (perhaps limited) RAM that is available. So the JVMs are competing for the available RAM. To the degree that the "heap space" is part of the RAM, the heap spaces are not separate. In particular, if one JVM runs a greedy application that uses lots of heap space (and thus lots of RAM), so the total working set of the JVMs exceeds the RAM, all the JVMs will slow down.

Upvotes: 0

greuze
greuze

Reputation: 4398

Every JVM will have its own heap memory (and every heap memory will contain a lot of objects). You can look to this article for further clarification: http://javarevisited.blogspot.com.es/2011/05/java-heap-space-memory-size-jvm.html

Upvotes: 1

KhAn SaAb
KhAn SaAb

Reputation: 5376

When an application creates a new object, the JVM sub-allocates a contiguous area of heap memory to store it See THIS

Upvotes: 0

Related Questions