Ryan Ryan - 1 month ago 14
Java Question

Is heap being shared to multiple threads?

I want to understand this, but when i set max heap size, does each thread in a multi-threaded environment creates their own heap and has the same size?

Answer

... does each thread in a multi-threaded environment creates their own heap and has the same size?

No. There is a single heap that is shared by all threads in the Java process.

It is possible to run a JVM with TLABs (thread local allocation buffers) to reduce allocation-related contention in a multi-threaded application. However, these are just regions with the Eden space of the Java heap. Not separate heaps. And besides, objects will be moved elsewhere by the GC as required.

References:

Comments