You’re essentially running out of memory to run the process smoothly. Options that come to mind:
- Specify more memory like you mentioned, try something in between like
-Xmx512m
first - Work with smaller batches of
HashMap
objects to process at once if possible - If you have a lot of duplicate strings, use
String.intern()
on them before putting them into theHashMap
- Use the
HashMap(int initialCapacity, float loadFactor)
constructor to tune for your case