We have some legacy code that was written in the early 2000s that was running fine till now, except when we added more users to the system it had daily OutOfMemory exceptions
We are going to redo the project from ground up, but we want to best use the existing code base.
The code has thousands (yes not the best design) of HashMaps that are only modified in a loop on creation and after that remain readonly.
When i run Memory analyser it says that there is 15% of the heap consists of unused space in HahsMaps.
For these instances if we use reflection to make the entry set accessible and resize it so the size is equal to the actual needed, will iterators fail?
After initial construction these maps are read only caches. We are running the code on Java 6 and few instances on Java 8. wont be upgrading the JVM version, in another 10-12 months the new code will be in production and replace the current.
I know we can give a better initial size when creating the hash map but that is a lot of work compared to one function that resizes a map based on current size. ALso most of the maps are part of libraries (that i do not have access to source code) and these do nt expose the the constructor that accepts size. they call default constructor of their internal HashMap only.