-1

As clear from the answer each application will run in a specific Java Virtual Machine Instance.And it is clear from this post that java string is immutable and JVM sets aside a special area of memory called the "String constant pool" to store strings.

My question is that if there is a single shared String constant pool for each web application or JVM, OR there is a separate String constant pool for each web application and jvm instance.

Holger
  • 285,553
  • 42
  • 434
  • 765
Haseeb Anser
  • 494
  • 1
  • 5
  • 19

1 Answers1

4

A string pool can not be shared between different JVMs. It is implemented as a hash table of references to the actual String objects which live in the particular heap of each JVM. Since references to different heaps are not compatible, as each JVM has its own logical address space, the hash table can’t be shared.

There is a mechanism to share common data between JVMs, Class Data Sharing, which uses a preprocessed form of common libraries, usually of the JRE. Besides the class and member definitions and the byte code, this naturally contains all string constants, but that’s only the data, using the data to create a Java String object with a distinct identity and adding a reference to the pool is still subject to each JVM.

Holger
  • 285,553
  • 42
  • 434
  • 765