wkk91193 commented on a change in pull request #524: FINERACT-428
Parallelization of Jobs : Parallelizing and paging of recalculate interest for
loans
URL: https://github.com/apache/fineract/pull/524#discussion_r352268322
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanSchedularServiceImpl.java
##########
@@ -184,4 +191,133 @@ public void recalculateInterest() throws
JobExecutionException {
}
-}
+ @Override
+ @CronTarget(jobName = JobName.RECALCULATE_INTEREST_FOR_LOAN)
+ public void recalculateInterest(Map<String, String> jobParameters) {
+ //gets the officeId
+ final String officeId = jobParameters.get("officeId");
+ logger.info(officeId);
+ Long officeIdLong=Long.valueOf(officeId);
+ //gets the Office object
+ final Office office =
this.officeRepository.findOne(officeIdLong);
+ if(office == null)
+ throw new OfficeNotFoundException(officeIdLong);
+ final int
threadPoolSize=Integer.parseInt(jobParameters.get("thread-pool-size"));
+ final int
batchSize=Integer.parseInt(jobParameters.get("batch-size"));
+
+ recalculateInterest(office,threadPoolSize,batchSize);
+ }
+
+ @Override
+ public void recalculateInterest(Office office, int threadPoolSize, int
batchSize) {
+ final int pageSize = batchSize * threadPoolSize;
+
+ //initialise the executor service with fetched configurations
+ final ExecutorService executorService =
Executors.newFixedThreadPool(threadPoolSize);
+
+ Long maxLoanIdInList = 0L;
+ final String officeHierarchy = office.getHierarchy() + "%";
+
+ //Get the loanIds from service
+ List<Long> loanIds = this.loanReadPlatformService
+ .fetchLoansForInterestRecalculation(pageSize,
maxLoanIdInList, officeHierarchy);
+
+ // gets the loanIds data set iteratively and call addAccuruals
for that paginated dataset
+ do {
+ int totalFilteredRecords = loanIds.size();
+ logger.info("Starting accrual - total filtered records
- " + totalFilteredRecords);
+ recalculateInterest(loanIds, threadPoolSize, batchSize,
+ executorService);
+ maxLoanIdInList+=pageSize+1;
+ loanIds = this.loanReadPlatformService
+
.fetchLoansForInterestRecalculation(pageSize, maxLoanIdInList, officeHierarchy);
+ } while (!CollectionUtils.isEmpty(loanIds));
Review comment:
@vorburger I just made them thread-safe. Thanks for your suggestions
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services