• Post Reply Bookmark Topic Watch Topic
  • New Topic

String pool confusion.  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does each Java application has separate String pool or all apps share a common pool? To further elaborate, if I have
String str1 = "Brendon" in program 1
String str2 = "Brendon" in program 2
Then will str2 get the same string as that was in str1?
 
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, each java application runs in its own process with its own heap.
So in your example str1 will be in a pool in the first process's heap and str2 will be in a pool in the second process's heap.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brendon McCullum wrote: Does each Java application has separate String pool or all apps share a common pool?

As Steffe said: Yes.

To further elaborate, if I have...

Ah. Unfortunately that muddies the waters a bit, because it depends how you run each program.

If you run them separately from the command line - ie, as separate applications - then what Steffe said still applies; but if you run program 2 from program 1 (or run both from some "launcher" program) - for example, as a Runnable - then they will both be in the same JVM, and therefore share the same pool.

HIH

Winston
 
Steffe Wilson
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:if you run program 2 from program 1 (or run both from some "launcher" program) - for example, as a Runnable - then they will both be in the same JVM, and therefore share the same pool.

Sure, but that would make them threads in common parlance, not programs.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!