Here's the resolution to bug: [ #474206 ] OutOfMemoryError when sending to Queue
There were 2 problems causing this error:
(1) The TextMessage implementation was creating a bigger than required buffer to hold the text of the message. This was causing a TextMessage to take up more memory than required by the message.
(2) The Server was holding all the messages "in memory". So eventually if you send enough messages to the server without another client consuming the messages, the server will throw an OutOfMemoryError.
Both of these problems have been fixed in the current JBossMQ version in the CVS HEAD.
JBossMQ now has a MessageCache object that monitors the amount of memory that the JVM is using and that starts swapping messages out to disk when memory usage start getting too high. The two main parameters that configure the MessageCache are:
- HighMemoryMark : Once the memory usage of the VM hits this mark, the MessageCache will start evaluating messages to move to disk.
- MaxMemoryMark : As memory usage gets closer to the MaxMemoryMark, the Cache will become more agressive in terms of how many messages get swapped to disk. NOTE: If the memory usage hits the MaxMemoryMark, the cache will try to move ALL messages in the cache to disk.
This Cache implementation uses SoftRefrences to keep message in memory as long as possible until the Garbage Collector sees a need to free up memory. This increases the chance that a message will be in memory even if it has been swapped to disk. So it would help avoid another IO operation to read the message.
Please Try it out. The default HighMemoryMark and MaxMemoryMark settings have been set really high, so you may need to adjust them (in deploy/jbossmq-service.xml)