I've got an MDB which consumes messages from a queue, and then invokes a stateless EJB to perform some db operations. Something like this:
public class TestMDB implements MessageListener
{
@EJB
private UpdateService updateSvc;
@Override
public void onMessage(Message message)
{
try
{
updateSvc.updateSystemStatuses();
}
catch(Exception e)
{
// log error
}
}
}
In the code above, if the updateSystemStatuses() call throws a RuntimeException, this seems to cause a memory leak. I've accelerated the process by inducing updateSystemStatuses() to throw RuntimeExceptions, and when this happens CPU usage and memory usage spike (as observed in JVisualVM) until I start to get OutOfMemoryErrors.
If I modify the code to throw the RuntimeExceptions out of onMessage, the resource leak seems to go away completely:
public class TestMDB implements MessageListener
{
@EJB
private UpdateService updateSvc;
@Override
public void onMessage(Message message)
{
try
{
updateSvc.updateSystemStatuses();
}
catch(RuntimeException e)
{
//log error
throw e;
}
catch(Exception e)
{
//log error
}
}
}
I'm aware that throwing a RuntimeException out of an EJB method will cause a transaction rollback, and I assume that has something to do with what I'm seeing, but beyond that I'm not clear on what's going on here. Is the resource leak a Glassfish bug? Am I handling exceptions in my MDB the correct way?
I'm running Glassfish 3.1.2.2 on Java 1.6.0_35, using Eclipselink and Oracle 11G.