Below Java syntax is throwing Java memory Heap issue in Openshift while invoking the data from the Mongodb database.Is there any way to know where the memory leakage is happening.Is memory will be reduced if we use Java 8 for each streams instead of for loop .Can anyone help me with Java8 for each synatx with the Pojo class .Here Amount is the POJO class. Or Any other suggestions also can be appreciated to reduce the memory for too many requests.
public String getAmountDetails( @RequestParam("system") @Valid String system,
@RequestParam("Claims") BigDecimal Claims,
@RequestParam("Bills") BigDecimal totalOfCommissions,
@RequestParam("taxes") BigDecimal totalOfSurcharges,
@RequestParam("userDetails") BigDecimal userDetails,
) throws Exception {
Query Query = new Query();
if (system != null && !system.isEmpty())
Query.addCriteria(Criteria.where("system").is(system));
List<Amount> amount = new ArrayList<>();
amount = mongoOps.find(Query, Amount.class);
amount.addAll(Amount);
totalAmount = new Amount();
if (Amount.isEmpty()) {
totalAmount.setSystem(system);
totalAmount.setClaims(BigDecimal.ZERO);
totalAmount.setBillsBigDecimal.ZERO);
totalAmount.setTaxes(BigDecimal.ZERO);
totalAmount.setuserDetails(BigDecimal.ZERO);
totalAmount.setStatus("Success");
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(totalAmount);
}
BigDecimal claims = new BigDecimal(0);
BigDecimal bills = new BigDecimal(0);
BigDecimal taxes = new BigDecimal(0);
BigDecimal userDeatils = new BigDecimal(0);
for (Amount amount : getAmount) {
if (null != amount.getClaims()) {
claimsAmt = claimsAmt.add(amount.getclaimsAmt().bigDecimalValue());
}
if (null != amount.getBillsAmt()) {
billslAmt = billsAmt.add(amount.getBillsAmt().bigDecimalValue());
}
if (null != amount.gettaxesAmt()) {
taxesAmt = taxesAmt.add(amount.getTaxesAmt().bigDecimalValue());
}
totalAmount.setClaims(claimsAmt);
totalAmount.setbills(billsAmt);
totalAmount.settaxesAmt(taxesAmt);
}
}