I have a mysql database which get filled with an object that contains a Map with a timestamp (long) and an object (safeboxForLongString).
The String in the safebox is from 5-15MB big.
My Problem is that after ~30 minutes of requesting the String data from the server my RAM Memory is already at 11-12 GB. I tried already to call System.gc and clear the previous filled TreeMap. But no success.
Isn't the purpose of a backed database that I don't have to use all my RAM?
I just cannot finish the process of collecting the server data because I always fail at that problem. Please help me.
Here the relevant code
//fill the Database
Main.getAllAvailableEntries().forEach(entryName -> {
final long[] id = {0};
treeMapWrapperRepo.findAll().forEach(entry -> {
if (entry.getCurrency().equals(entryName)) {
id[0] = entry.getMultiHashMapWrapper_id();
}
});
if (id[0] == 0) {
System.out.println("Forming: " + entryName);
final TreeMapWrapper treeMapWrapper = new TreeMapWrapper(entryName);
TreeMap<Long, SafeBoxForLongString> timeStampToSafeBoxMap = new TreeMap<>();
int start = startDateInThePast;
while (start - length >= 0) {
long startDate = instant.minus(start, ChronoUnit.DAYS).getEpochSecond();
long endDate = instant.minus(start - length, ChronoUnit.DAYS).getEpochSecond();
String getReponseWith45DaysLength = dataController.getDataForDB(entryName, startDate, endDate, String.valueOf(resolution));
while (getReponseWith45DaysLength.isEmpty()) {
getReponseWith45DaysLength = dataController.getDataForDB(entryName, startDate, endDate, String.valueOf(resolution));
}
SafeBoxForLongString safeBoxForLongString = new SafeBoxForLongString(getReponseWith45DaysLength);
safeBoxForLongString.setMultiHashMapWrapper(treeMapWrapper);
timeStampToSafeBoxMap.put(startDate, safeBoxForLongString);
treeMapWrapper.setLongSafeTimeAndReponseMap(timeStampToSafeBoxMap);
start--;
}
treeMapWrapperRepo.save(treeMapWrapper);
treeMapWrapper.getLongSafeTimeAndReponseMap().clear();
System.gc();
}
});
Edit: Like one stacker said, treeMapWrapperRepo.findAll(). was the problem.