galovics commented on code in PR #4164:
URL: https://github.com/apache/fineract/pull/4164#discussion_r1846827337


##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTasklet.java:
##########
@@ -104,16 +109,34 @@ private void markEventsAsSent(List<Long> eventIds) {
         // Partitioning dataset to avoid exception: PreparedStatement can have 
at most 65,535 parameters
         final int partitionSize = 
fineractProperties.getEvents().getExternal().getPartitionSize();
         List<List<Long>> partitions = Lists.partition(eventIds, partitionSize);
+        final ThreadPoolTaskExecutor executor = getThreadPoolTaskExecutor();
+        final FineractContext context = ThreadLocalContextUtil.getContext();
         partitions //
                 .forEach(partitionedEventIds -> {
-                    measure(() -> {
-                        repository.markEventsSent(partitionedEventIds, sentAt);
-                    }, timeTaken -> {
-                        log.debug("Took {}ms to update {} events", 
timeTaken.toMillis(), partitionedEventIds.size());
+                    executor.execute(() -> {
+                        measure(() -> {
+                            ThreadLocalContextUtil.init(context);
+                            repository.markEventsSent(partitionedEventIds, 
sentAt);
+                        }, timeTaken -> {
+                            log.debug("Took {}ms to update {} events", 
timeTaken.toMillis(), partitionedEventIds.size());
+                        });
                     });
                 });
     }
 
+    @Nonnull
+    private ThreadPoolTaskExecutor getThreadPoolTaskExecutor() {
+        if (threadPoolTaskExecutor == null) {
+            threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
+            
threadPoolTaskExecutor.setCorePoolSize(fineractProperties.getEvents().getExternal().getThreadPoolCorePoolSize());
+            
threadPoolTaskExecutor.setMaxPoolSize(fineractProperties.getEvents().getExternal().getThreadPoolMaxPoolSize());
+            
threadPoolTaskExecutor.setQueueCapacity(fineractProperties.getEvents().getExternal().getThreadPoolQueueCapacity());
+            
threadPoolTaskExecutor.setThreadNamePrefix("Fineract-external-event-");

Review Comment:
   let's just name it external-events-



##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTasklet.java:
##########
@@ -104,16 +109,34 @@ private void markEventsAsSent(List<Long> eventIds) {
         // Partitioning dataset to avoid exception: PreparedStatement can have 
at most 65,535 parameters
         final int partitionSize = 
fineractProperties.getEvents().getExternal().getPartitionSize();
         List<List<Long>> partitions = Lists.partition(eventIds, partitionSize);
+        final ThreadPoolTaskExecutor executor = getThreadPoolTaskExecutor();
+        final FineractContext context = ThreadLocalContextUtil.getContext();
         partitions //
                 .forEach(partitionedEventIds -> {
-                    measure(() -> {
-                        repository.markEventsSent(partitionedEventIds, sentAt);
-                    }, timeTaken -> {
-                        log.debug("Took {}ms to update {} events", 
timeTaken.toMillis(), partitionedEventIds.size());
+                    executor.execute(() -> {
+                        measure(() -> {
+                            ThreadLocalContextUtil.init(context);
+                            repository.markEventsSent(partitionedEventIds, 
sentAt);
+                        }, timeTaken -> {
+                            log.debug("Took {}ms to update {} events", 
timeTaken.toMillis(), partitionedEventIds.size());
+                        });
                     });
                 });
     }
 
+    @Nonnull
+    private ThreadPoolTaskExecutor getThreadPoolTaskExecutor() {

Review Comment:
   Don't create this inside the Tasklet. Extract it to the tasklet's config 
(that's why it's there) and have the threadpool configured there as a bean.



##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/event/external/repository/ExternalEventRepository.java:
##########
@@ -40,6 +41,7 @@ public interface ExternalEventRepository extends 
JpaRepository<ExternalEvent, Lo
     void deleteOlderEventsWithSentStatus(@Param("status") ExternalEventStatus 
status,
             @Param("dateForPurgeCriteria") LocalDate dateForPurgeCriteria);
 
+    @Transactional

Review Comment:
   frankly speaking, defining the transactional boundary on the repository 
level is often a code-smell. With transactionality you want to have atomicity 
across an operation, not a single repository call. I'd move this one level up 
(and since you're using a lambda there, I'd use TransactionTemplate for it)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to