我有一个 java webobjects 应用程序,它在 Red Hat 上运行时显示内存泄漏问题,但在 Mac OS X 上运行时我们没有这样的问题。JVM 是相似的。
Mac OS X 10.6.5 使用来自 Apple Red Hat EL 5.0 的 java 1.6.0_22 64 位,使用来自 Sun 的 java 1.6.0_20 64 位
我将它配置为在内存不足时执行堆转储,并使用 eclipse 内存分析器工具分析它表明问题出在创建线程的部分代码中,该线程将 HTTP 请求发送到 Web 服务。创建线程的原因是对请求实现超时,因为 Web 服务有时不可用。
有没有人有任何想法?
WOHTTPConnection connection = new WOHTTPConnection(host, port);
WORequest request = new WORequest(strMethod, strQuery, strHttpVersion, nsdHeader, content, null);
WebServiceRequester theRequester = new WebServiceRequester(connection, request);
Thread requestThread = new Thread(theRequester);
requestThread.start();
try {
requestThread.join(intTimeoutSend); //timeout in milliseconds = 10000
if ( requestThread.isAlive() ) {
requestThread.interrupt();
}
} catch(InterruptedException e) {
}
requestThread = null;
if(!theRequester.getTfSent()) {
return null;
}
WOResponse response = connection.readResponse();
...
class WebServiceRequester implements Runnable {
private WORequest theRequest;
private WOHTTPConnection theConnection;
private boolean tfSent = false;
public WebServiceRequester(WOHTTPConnection c, WORequest r) {
theConnection = c;
theRequest = r;
}
public void run() {
tfSent = theConnection.sendRequest(theRequest);
}
public boolean getTfSent() {
return tfSent;
}
}
编辑:eclipse内存分析器工具报告的泄漏类名:
1,296 instances of "java.lang.Thread", loaded by "<system class loader>" occupy 111,947,632 (43.21%) bytes.
1,292 instances of "er.extensions.eof.ERXEC", loaded by "java.net.URLClassLoader @ 0x2aaab375b7c0" occupy 37,478,352 (14.46%) bytes.
1,280 instances of "er.extensions.appserver.ERXRequest", loaded by "java.net.URLClassLoader @ 0x2aaab375b7c0" occupy 27,297,992 (10.54%) bytes.