int pageSize = 5000; int totalSize = rewardAmounts.size(); int totalPage = totalSize / pageSize; if (pageSize > totalSize) { rewardAmountService.updateBatch(rewardAmounts); } else { for (int i = 0; i < totalPage; i++) { rewardAmountService.updateBatch(rewardAmounts.subList(i * pageSize, (i + 1) * pageSize)); } if (totalSize % pageSize != 0) { rewardAmountService.updateBatch(rewardAmounts.subList(totalSize - totalSize % pageSize, totalSize)); } }