thomasmueller commented on code in PR #2679:
URL: https://github.com/apache/jackrabbit-oak/pull/2679#discussion_r2697339572


##########
oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java:
##########
@@ -572,24 +567,7 @@ ExecutorService getExecutorService(){
     }
 
     private ExecutorService createExecutor() {
-        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 60L, 
TimeUnit.SECONDS,
-                new LinkedBlockingQueue<>(), new ThreadFactory() {
-            private final AtomicInteger counter = new AtomicInteger();
-            private final Thread.UncaughtExceptionHandler handler = (t, e) -> 
log.warn("Error occurred in asynchronous processing ", e);
-            @Override
-            public Thread newThread(@NotNull Runnable r) {
-                Thread thread = new Thread(r, createName());
-                thread.setDaemon(true);
-                thread.setPriority(Thread.MIN_PRIORITY);
-                thread.setUncaughtExceptionHandler(handler);
-                return thread;
-            }
-
-            private String createName() {
-                return "oak-lucene-" + counter.getAndIncrement();
-            }
-        });
-        executor.setKeepAliveTime(1, TimeUnit.MINUTES);
+        ThreadPoolExecutor executor = 
ExecutorHelper.linkedQueueExecutor(INDEX_COPIER_POOL_SIZE, "oak-lucene-%d", (t, 
e) -> log.warn("Error occurred in asynchronous processing ", e));

Review Comment:
   ```suggestion
           ThreadPoolExecutor executor = ExecutorHelper.linkedQueueExecutor(
                   INDEX_COPIER_POOL_SIZE, 
                   "oak-lucene-%d", (t, e) -> log.warn("Error occurred in 
asynchronous processing ", e));
   ```



##########
oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/ExtractedTextCache.java:
##########
@@ -346,26 +344,7 @@ private synchronized void createExecutor() {
             return;
         }
         log.debug("ExtractedTextCache createExecutor {}", this);
-        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 
EXTRACTION_MAX_THREADS,
-                60L, TimeUnit.SECONDS,
-            new LinkedBlockingQueue<>(), new ThreadFactory() {
-            private final AtomicInteger counter = new AtomicInteger();
-            private final Thread.UncaughtExceptionHandler handler = (t, e) -> 
log.warn("Error occurred in asynchronous processing ", e);
-            @Override
-            public Thread newThread(@NotNull Runnable r) {
-                Thread thread = new Thread(r, createName());
-                thread.setDaemon(true);
-                thread.setPriority(Thread.MIN_PRIORITY);
-                thread.setUncaughtExceptionHandler(handler);
-                return thread;
-            }
-
-            private String createName() {
-                int index = counter.getAndIncrement();
-                return "oak binary text extractor" + (index == 0 ? "" : " " + 
index);
-            }
-        });
-        executor.setKeepAliveTime(1, TimeUnit.MINUTES);
+        ThreadPoolExecutor executor = 
ExecutorHelper.linkedQueueExecutor(EXTRACTION_POOL_SIZE, 
"oak-binary-text-extractor-%d", (t, e) -> log.warn("Error occurred in 
asynchronous processing ", e));

Review Comment:
   ```suggestion
           ThreadPoolExecutor executor = ExecutorHelper.linkedQueueExecutor(
                   EXTRACTION_POOL_SIZE, 
                   "oak-binary-text-extractor-%d", (t, e) -> log.warn("Error 
occurred in asynchronous processing ", e));
   ```



##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java:
##########
@@ -174,26 +171,7 @@ protected void bindIndexInfoProviders(IndexInfoServiceImpl 
indexInfoService) {
     }
 
     private ThreadPoolExecutor createExecutor() {
-        ThreadPoolExecutor executor = new ThreadPoolExecutor(0, 5, 60L, 
TimeUnit.SECONDS,
-                new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
-            private final AtomicInteger counter = new AtomicInteger();
-            private final Thread.UncaughtExceptionHandler handler =
-                    (t, e) -> log.warn("Error occurred in asynchronous 
processing ", e);
-
-            @Override
-            public Thread newThread(@NotNull Runnable r) {
-                Thread thread = new Thread(r, createName());
-                thread.setDaemon(true);
-                thread.setPriority(Thread.MIN_PRIORITY);
-                thread.setUncaughtExceptionHandler(handler);
-                return thread;
-            }
-
-            private String createName() {
-                return "oak-lucene-" + counter.getAndIncrement();
-            }
-        });
-        executor.setKeepAliveTime(1, TimeUnit.MINUTES);
+        ThreadPoolExecutor executor = 
ExecutorHelper.onDemandSingleThreadLinkedQueueExecutor("oak-lucene-%d", (t, e) 
-> log.warn("Error occurred in asynchronous processing ", e));

Review Comment:
   ```suggestion
           ThreadPoolExecutor executor = 
ExecutorHelper.onDemandSingleThreadLinkedQueueExecutor(
                   "oak-lucene-%d", (t, e) -> log.warn("Error occurred in 
asynchronous processing ", e));
   ```



##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatistics.java:
##########
@@ -69,12 +67,9 @@ public class ElasticIndexStatistics implements 
IndexStatistics {
     private static final String REFRESH_SECONDS = 
"oak.elastic.statsRefreshSeconds";
     private static final Long REFRESH_SECONDS_DEFAULT = 60L;
 
-    private static final ExecutorService REFRESH_EXECUTOR = new 
ThreadPoolExecutor(
-            0, 4, 60L, TimeUnit.SECONDS,
-            new LinkedBlockingQueue<>(),
-            
BasicThreadFactory.builder().namingPattern("elastic-statistics-cache-refresh-thread-%d").daemon().build()
-    );
+    private static final int REFRESH_POOL_SIZE = 4;
 
+    private static final ExecutorService REFRESH_EXECUTOR = 
ExecutorHelper.linkedQueueExecutor(REFRESH_POOL_SIZE, 
"elastic-statistics-cache-refresh-%d");

Review Comment:
   ```suggestion
       private static final ExecutorService REFRESH_EXECUTOR = 
ExecutorHelper.linkedQueueExecutor(
               REFRESH_POOL_SIZE, "elastic-statistics-cache-refresh-%d");
   ```



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