我有一个 Spring Boot 应用程序,它每两分钟执行一次计划任务,以从时间序列中获取数据并通过 HTTP 请求对其执行一些计算,然后将结果存储回时间序列中。
问题是随着每次迭代,内存消耗都在增加。我为此尝试了 2 GB 和 4 GB 内存,但一段时间后它的内存耗尽,导致堆内存错误。下面是一个示例代码,可以让您大致了解我在做什么。
@Scheduled(cron = "0 0/2 * * * ?")
public void run() {
try {
log.info(new Timestamp(System.currentTimeMillis()).toString() + " -- Starting analytics execution.");
AnalyticResponseModel timeseriesResponse = null;
//Get input for Analytics Execution
timeseriesResponse = retrieveDataPointsCurrent(TagsDataBuffer.TAGS);
//Prepare payload for model execution request
String payload = mapper.writeValueAsString(timeseriesResponse);
RequestBody requestBody = RequestBody.create(JSON, payload);
Request request = new Request.Builder().url(analyticModelURL).header("Content-Type", "application/json")
.header("Accept", "application/json").post(requestBody).build();
if( timeseriesResponse.getData().getTime_series().get("time_stamp").isEmpty()) {
log.error("No Recent Data");
return;
}
dataTimestamp = (long) timeseriesResponse.getData().getTime_series().get("time_stamp").get(0);
log.info(new Timestamp(System.currentTimeMillis()).toString() + " -- Fetching Input data.");
//Execute request
Response response = client.newCall(request).execute();
parseAndSaveOutput( response);
} catch (Exception e) {
log.error(e.getMessage());
}
}
1-如何检查内存泄漏的位置以及如何在云代工厂中进行泄漏 2-任何替代/更好的方法