可能存在内存泄漏 CXF 2.4.2 Glassfish 3
我正在努力理解代码中可能存在的内存泄漏。我有一个简单的 Web 服务,它接收 XML 格式的消息并将它们写入数据库。我注意到,在处理大约 500K 消息后,应用程序因内存不足错误而终止。经过一段陡峭的学习曲线后,我设法分析正在运行的应用程序,并很快发现每次调用服务时,堆上都会保存一个 Web 服务实现对象。为了减少我的代码导致的可能性,我修改了实现,以便它在不执行任何操作后返回。然而,堆继续增长。我的环境是 Glassfish 3、CXF 2.4.2 和 Eclipse(动态 Web 项目)。我已经在下面包含了服务和实现类。为了更清楚一点——处理 500,000 条消息后,堆上有 500,000 个 HL7ServiceImpl。
我对此真的很茫然,因此我们将不胜感激。
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,以防万一其他人发现这个问题。该问题似乎与 Glassfish 的本地 Metro 实现和 CXF 之间的冲突有关。从 CXF 迁移到 Metro 解决了这个问题。
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.