I read this stack overflow page about solving this problem and tried adding the command line option -XX:-UseGCOverheadLimit and also "-Xmx" arguments. However, my program still threw the out of memory error.
The program saves a large number (>40,000 keys) of words into a MultiKeyMap and is running on a server with plenty of memory.
Any suggestions on how I can aviod the error?