I am struggling to understand a possible memory leak in my code. I have a simple web service that receives XML formatted messages and writes them to a database. I have noticed that after processing approximately 500K messages the application dies with an out of memory error. After a steep learning curve I managed to profile the running application and found very quickly that a web service implementation object was being held on the heap for each invocation of the service. To reduce the possibility that my code was the cause I modified the implementation so that it returned after doing nothing. However, the heap continued to grow. My environment, is Glassfish 3, CXF 2.4.2 and Eclipse (dynamic web project). I have included the service and implementation classes below. To try to be a bit clearer – after processing 500,000 messages there are 500,000 HL7ServiceImpl on the heap.
I am really at a loss with this so any assistance would be appreciated.
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(name = "HL7Service", targetNamespace = "http://ws.foo.bar.com/")
public interface HL7Service {
@WebMethod(operationName = "submit", action = "urn:Submit")
public void submit(@WebParam(name = "msg") String msg);
}
import javax.jws.WebService;
@WebService(targetNamespace = "http://ws.foo.bar.com/", endpointInterface = "com.bar.foo.ws.HL7Service", portName = "HL7ServiceImplPort", serviceName = "HL7ServiceImplService")
public class HL7ServiceImpl implements HL7Service {
public void submit (String msg) {
// if (msg == null)
// return ("NAK");
// else
// EventQueue.getInstance().submit(msg);
//
// return "ACK";
if (msg != null) { // temp
// DO nothing
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="hl7service"
implementor="com.bar.foo.ws.HL7ServiceImpl" address="/hl7service">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>
Ok, just in case someone else finds this question. The issue seemed to be related to a conflict between Glassfish’s native Metro implementation and CXF. Moving from CXF to Metro solved the problem.