How String Pool is implemented and how to configure:
I think as a Java Professional, you know what is String pool. But do you know the limit of String pool, how to configure the limit of it. Even you can create your own String Pool when you are working with millions of Strings and you need performance.
The string pool is implemented as a fixed capacity HashMap and each bucket in the HashMap contains a list of strings with the same hash code.
The default string pool size is 1009 (it is present in the source code). It was a constant in the early versions of Java 6 and became configurable between Java6u30 and Java6u41. It is configurable in Java 7 from the beginning. You need to specify -XX:StringTableSize=N, where N is the string pool map size. Ensure it is a prime number for the better performance.
Depends on your application requirements, you can set the string pool size to a higher value in advance.
What will happen when it crosses the limit, its your turn to test it. Create huge number of String literals through looping then check then check is it allowed or not.
you need to think about the memory consumption when the memory data set size grows to several hundred megabytes or more. In this situation, allocating 8-16 MB for a string pool with one million entries seems to be a reasonable trade off (do not use 1,000,000 as a -XX:StringTableSize value – it is not prime; use 1,000,003 instead).
Latest posts by Gopal Das (see all)
- Salesforce Certified Platform Developer I – Winter ’18 Release Exam - November 23, 2017
- Salesforce Certified Platform App Builder – Winter ’18 Release Exam - November 22, 2017
- Salesforce Certified Administrator – Winter’ 18 Release Exam - November 21, 2017