本文介紹了WebSphere 8內存泄漏的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在WebSphere8.5上部署了一個應用程序(該應用程序是使用java8/Spring4開發的),并且每天都會收到許多轉儲文件,因此我決定使用Eclipse Memory Analyzer對其進行分析,結果是:
問題是我沒有使用AXIS來調用Web服務,我只使用Jersy來調用睡覺Web服務,并且
SOAP Web服務的默認JDK類SoapConnection,以下是一些代碼示例:
對于SOAP:
public String soapBind(List<ContextItem> dic, String serviceId, String urlWs, String applicationId) throws SOAPException, Exception {
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
SOAPMessage msg = soapCall(dic, serviceId, applicationId); // Send SOAP Message to SOAP Server
String url = urlWs;
LOGGER.info("CALLING WS ....");
SOAPMessage soapResponse = soapConnection.call(msg, url);
// print SOAP Response
//soapResponse.writeTo(System.out);
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapResponse.writeTo(out);
soapConnection.close();
String strMsg = new String(out.toByteArray());
LOGGER.info("Response SOAP Message: {}",strMsg);
return strMsg;
} catch (SOAPException ex) {
throw ex;
} catch (UnsupportedOperationException ex) {
throw ex;
} catch (Exception ex) {
throw ex;
}
}
睡覺:
Client client = Client.create();
WebResource webResource = client
.resource(urlFicheClientProf);
//
ServiceContext serviceContext = this.getServiceContext();
//
ObjectMapper mapper = new ObjectMapper();
ClientResponse response = webResource
.queryParam("customerId", radical)
.queryParam("serviceContext",
URLEncoder.encode(mapper.writeValueAsString(serviceContext),
"UTF-8"))
.post(ClientResponse.class);
我想知道為什么會發生Axis.Client內存不足,以及如何修復它。如果有人能幫我弄清楚,我將不勝感激。
推薦答案
使用RESTTemplate而不是SOAPConnection修復了內存泄漏:
final RestTemplate restTemplate = new RestTemplate();
final HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "text/xml");
final HttpEntity<String> request = new HttpEntity<>(message, headers);
final String result = restTemplate.postForObject(wsUrl, request, String.class);
return result;
這篇關于WebSphere 8內存泄漏的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,