Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is string pool measured in terms of buckets in java

While going through this article about String pool and its changes over the years, I came across the following statement:

Prior to Java 7u40, the default pool size was 1009 buckets but this value was subject to a few changes in more recent Java versions. To be precise, the default pool size from Java 7u40 until Java 11 was 60013 and now it increased to 65536.

So, what are buckets in String pool? How are these comparable to the number of interned Strings? Is the concept similar to buckets in hashmaps?

like image 426
YetAnotherBot Avatar asked Oct 15 '22 14:10

YetAnotherBot


1 Answers

So, what are buckets in String pool?

The String pool is basically a hash table. A hash table contains buckets or slots.

How are these comparable to the number of interned Strings?

It's implementation-defined (JVM-specific) and depends on how many entries a single bucket stores. Ideally, one bucket keeps one entry.

Is the concept similar to buckets in hashmaps?

Yes, it's the same idea.

Why is the default pool size growing? (my question)

The more buckets are allocated, the lower the load factor gets, which positively affects performance. I guess the initial number of entries occupied in the table grows, so it's important to keep the load factor updated (at least at the same level).

like image 118
Andrew Tobilko Avatar answered Oct 21 '22 12:10

Andrew Tobilko