bhabegger commented on code in PR #2679:
URL: https://github.com/apache/jackrabbit-oak/pull/2679#discussion_r2681130056
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java:
##########
@@ -174,25 +172,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();
- }
- });
+ ThreadPoolExecutor executor = ExecutorHelper.linkedQueueExecutor(5,
"oak-lucene-%d", (t, e) -> log.warn("Error occurred in asynchronous processing
", e));
Review Comment:
In fact, this is part of the issue. In the original code the number of
threads is either 0 or 1. It will never go above 1 as the maximumPoolSize is
ignored in case of an unbounded queue (as per
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ThreadPoolExecutor.html):
> 2. Unbounded queues. Using an unbounded queue (for example a
[LinkedBlockingQueue](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/LinkedBlockingQueue.html)
without a predefined capacity) will cause new tasks to wait in the queue when
all corePoolSize threads are busy. Thus, no more than corePoolSize threads will
ever be created. (And _**the value of the maximumPoolSize therefore doesn't
have any effect.**_) This may be appropriate when each task is completely
independent of others, so tasks cannot affect each others execution; for
example, in a web page server. While this style of queuing can be useful in
smoothing out transient bursts of requests, it admits the possibility of
unbounded work queue growth when commands continue to arrive on average faster
than they can be processed.
(If fact in this particular case corePoolSize 0 it will go above but only to
1 thread).
--
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]