I have a Spring batch job which contains only one step that reads a CSV file(containing approximately 2000 rows) using a FlatFileItemReader
and writes the objects to the database. I have my own custom BeanWrapperFieldSetMapper
which maps the rows to objects. The chunk size is set to 50, so I am expecting after writing the objects from each batch (50 objects), the heap memory to be released of those objects.
Since I'm leveraging the batch processing, I'm expecting at each given time to only have 50 CreditCardDebt objects. But instead, while processing the last batch I find the heap memory to contain 2000 CreditCardDebt objects.
What am I missing?
My BeanWrapperFieldSetMapper implementation:
@Component("CREDIT_CARD_DEBT_FIELD_SET_MAPPER_TEST")
public class TestDebtFieldSetMapper extends BeanWrapperFieldSetMapper<CreditCardDebt> {
public TestDebtFieldSetMapper() {
super.setPrototypeBeanName("CREDIT_CARD_DEBT_FIELD_SET_MAPPER_TEST");
}
@NonNull
@Override
public CreditCardDebt mapFieldSet(FieldSet fieldSet) {
CreditCardDebt creditCardDebt = new CreditCardDebt();
creditCardDebt.setAccount(fieldSet.readString(0));
creditCardDebt.setCardholderId(fieldSet.readString(1));
creditCardDebt.setDueDate(convertToLocalDateViaInstant(fieldSet.readString(2)));
creditCardDebt.setDaysPastDue(fieldSet.readInt(3));
creditCardDebt.setOverdueAmount(fieldSet.readDouble(4));
creditCardDebt.setDirectDebitMinimumPayment(fieldSet.readDouble(5));
creditCardDebt.setDirectDebitBalance(fieldSet.readDouble(6));
creditCardDebt.setDirectDebitStatus(fieldSet.readChar(7));
creditCardDebt.setDirectDebitType(DirectDebitType.valueOf(fieldSet.readString(8)));
creditCardDebt.setCreatedDate(LocalDateTime.now());
creditCardDebt.setFileName("BAL");
return creditCardDebt;
}
private LocalDate convertToLocalDateViaInstant(String dateToConvert) {
DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyyMMdd");
return LocalDate.parse(dateToConvert, formatters);
}
java.lang.OutOfMemoryError: GC overhead limit exceeded.
So it looks like, the instances belonging to a batch are not cleaned after the job is done with that batch. Is that the expected behavior? – AndreiBeanWrapperFieldSetMapper
(or something else) does not hold items during the whole the job execution? – Mahmoud Ben Hassine