我有一个Java WebObjects应用程序,在Mac OS X上运行时没有内存泄漏问题,但在Red Hat上运行时存在此类问题。JVM相似。
Mac OS X 10.6.5使用来自Apple的64位Java 1.6.0_22, Red Hat EL 5.0使用来自Sun的64位Java 1.6.0_20。
我配置了它在内存不足时执行堆转储,并使用Eclipse Memory Analyzer工具分析表明问题出现在创建一个线程以向Web服务发送HTTP请求的代码部分。创建线程的原因是实现对请求的超时,因为Web服务有时无法访问。
请问有人有任何想法吗?
Mac OS X 10.6.5使用来自Apple的64位Java 1.6.0_22, Red Hat EL 5.0使用来自Sun的64位Java 1.6.0_20。
我配置了它在内存不足时执行堆转储,并使用Eclipse Memory Analyzer工具分析表明问题出现在创建一个线程以向Web服务发送HTTP请求的代码部分。创建线程的原因是实现对请求的超时,因为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.