You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2023/09/20 13:30:44 UTC
[lucene] branch branch_9x updated: Make TaskExecutor public (#12574)
This is an automated email from the ASF dual-hosted git repository.
javanna pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new f01ff9d1f51 Make TaskExecutor public (#12574)
f01ff9d1f51 is described below
commit f01ff9d1f5147eddb065f2f392896979d8570c65
Author: Luca Cavanna <ja...@apache.org>
AuthorDate: Wed Sep 20 15:27:56 2023 +0200
Make TaskExecutor public (#12574)
TaskExecutor is currently package private. We have scenarios where we
want to parallelize the execution and reuse it outside of its package,
hence this commit makes it public (and experimental).
Note that its constructor remains package private as it is supposed to
be created by the index searcher, and later retrieved from it via the
appropriate getter, which is also made public as part of this commit.
Co-authored-by: gf2121 <52...@users.noreply.github.com>
---
lucene/CHANGES.txt | 4 ++--
.../org/apache/lucene/search/IndexSearcher.java | 7 ++++++-
.../org/apache/lucene/search/TaskExecutor.java | 23 ++++++++++++++++++----
3 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 941c018fb2c..86c538eff18 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -7,7 +7,6 @@ http://s.apache.org/luceneversions
API Changes
---------------------
-(No changes)
New Features
---------------------
@@ -15,7 +14,8 @@ New Features
Improvements
---------------------
-(No changes)
+* GITHUB#12574: Make TaskExecutor public so that it can be retrieved from the searcher and used
+ outside of the o.a.l.search package (Luca Cavanna)
Optimizations
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
index c433490100f..3d293604383 100644
--- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
+++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
@@ -987,7 +987,12 @@ public class IndexSearcher {
return executor;
}
- TaskExecutor getTaskExecutor() {
+ /**
+ * Returns the {@link TaskExecutor} that this searcher relies on to execute concurrent operations
+ *
+ * @return the task executor
+ */
+ public TaskExecutor getTaskExecutor() {
return taskExecutor;
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java b/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java
index d416d70c2f5..6e64df31400 100644
--- a/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java
+++ b/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java
@@ -40,8 +40,10 @@ import org.apache.lucene.util.ThreadInterruptedException;
* calls, and not for potential {@link #invokeAll(Collection)} calls made from one of the tasks.
* This is to prevent deadlock with certain types of pool based executors (e.g. {@link
* java.util.concurrent.ThreadPoolExecutor}).
+ *
+ * @lucene.experimental
*/
-class TaskExecutor {
+public final class TaskExecutor {
// a static thread local is ok as long as we use a counter, which accounts for multiple
// searchers holding a different TaskExecutor all backed by the same executor
private static final ThreadLocal<Integer> numberOfRunningTasksInCurrentThread =
@@ -61,7 +63,7 @@ class TaskExecutor {
* @return a list containing the results from the tasks execution
* @param <T> the return type of the task execution
*/
- final <T> List<T> invokeAll(Collection<Task<T>> tasks) throws IOException {
+ public <T> List<T> invokeAll(Collection<Task<T>> tasks) throws IOException {
if (numberOfRunningTasksInCurrentThread.get() > 0) {
for (Task<T> task : tasks) {
task.run();
@@ -85,11 +87,24 @@ class TaskExecutor {
return results;
}
- final <C> Task<C> createTask(Callable<C> callable) {
+ /**
+ * Creates a task given the provided {@link Callable}
+ *
+ * @param callable the callable to be executed as part of the task
+ * @return the created task
+ * @param <C> the return type of the task
+ */
+ public <C> Task<C> createTask(Callable<C> callable) {
return new Task<>(callable);
}
- static class Task<V> extends FutureTask<V> {
+ /**
+ * Extension of {@link FutureTask} that tracks the number of tasks that are running in each
+ * thread.
+ *
+ * @param <V> the return type of the task
+ */
+ public static final class Task<V> extends FutureTask<V> {
private Task(Callable<V> callable) {
super(callable);
}