2525
2626import java .util .concurrent .ExecutorService ;
2727import java .util .concurrent .Executors ;
28- import java .util .concurrent .ForkJoinPool ;
29- import java .util .concurrent .ForkJoinWorkerThread ;
3028import java .util .concurrent .ScheduledThreadPoolExecutor ;
3129
3230import org .opengrok .indexer .analysis .Ctags ;
3836import org .opengrok .indexer .util .ObjectFactory ;
3937import org .opengrok .indexer .util .ObjectPool ;
4038
41- import static java .util .concurrent .ForkJoinPool .defaultForkJoinWorkerThreadFactory ;
42-
4339/**
4440 * Represents a container for executors that enable parallelism for indexing
4541 * across projects and repositories and also within any {@link IndexDatabase}
4642 * instance -- with global limits for all execution.
4743 * <p>A fixed-thread pool is used for parallelism across repositories, and a
48- * work-stealing {@link ForkJoinPool } is used for parallelism within any
44+ * {@link #lzIndexWorkExecutor } is used for parallelism within any
4945 * {@link IndexDatabase}. Threads in the former pool are customers of the
50- * latter, and the bulk of work is done in the latter pool. The work-stealing
51- * {@link ForkJoinPool } makes use of a corresponding fixed pool of {@link Ctags}
52- * instances.
53- * <p>Additionally there are pools for executing for history, for renamings in
46+ * latter, and the bulk of work is done in the latter pool.
47+ * The {@link #lzIndexWorkExecutor } makes use of a corresponding fixed pool
48+ * of {@link Ctags} instances.
49+ * <p>Additionally there are pools for executing for history, for renames in
5450 * history, and for watching the {@link Ctags} instances for timing purposes.
5551 */
5652public class IndexerParallelizer implements AutoCloseable {
5753
5854 private final RuntimeEnvironment env ;
5955 private final int indexingParallelism ;
6056
61- private LazilyInstantiate <ForkJoinPool > lzForkJoinPool ;
57+ private LazilyInstantiate <ExecutorService > lzIndexWorkExecutor ;
6258 private LazilyInstantiate <ObjectPool <Ctags >> lzCtagsPool ;
6359 private LazilyInstantiate <ExecutorService > lzFixedExecutor ;
6460 private LazilyInstantiate <ExecutorService > lzHistoryExecutor ;
@@ -82,7 +78,7 @@ public IndexerParallelizer(RuntimeEnvironment env) {
8278 */
8379 this .indexingParallelism = env .getIndexingParallelism ();
8480
85- createLazyForkJoinPool ();
81+ createIndexWorkExecutor ();
8682 createLazyCtagsPool ();
8783 createLazyFixedExecutor ();
8884 createLazyHistoryExecutor ();
@@ -99,10 +95,10 @@ public ExecutorService getFixedExecutor() {
9995 }
10096
10197 /**
102- * @return the forkJoinPool
98+ * @return the executor used for individual file processing in the 2nd stage of indexing
10399 */
104- public ForkJoinPool getForkJoinPool () {
105- return lzForkJoinPool .get ();
100+ public ExecutorService getIndexWorkExecutor () {
101+ return lzIndexWorkExecutor .get ();
106102 }
107103
108104 /**
@@ -166,7 +162,7 @@ public void close() {
166162 * call this method satisfactorily too.
167163 */
168164 public void bounce () {
169- bounceForkJoinPool ();
165+ bounceIndexWorkExecutor ();
170166 bounceFixedExecutor ();
171167 bounceCtagsPool ();
172168 bounceHistoryExecutor ();
@@ -175,11 +171,11 @@ public void bounce() {
175171 bounceXrefWatcherExecutor ();
176172 }
177173
178- private void bounceForkJoinPool () {
179- if (lzForkJoinPool .isActive ()) {
180- ForkJoinPool formerForkJoinPool = lzForkJoinPool .get ();
181- createLazyForkJoinPool ();
182- formerForkJoinPool .shutdown ();
174+ private void bounceIndexWorkExecutor () {
175+ if (lzIndexWorkExecutor .isActive ()) {
176+ ExecutorService formerIndexWorkExecutor = lzIndexWorkExecutor .get ();
177+ createIndexWorkExecutor ();
178+ formerIndexWorkExecutor .shutdown ();
183179 }
184180 }
185181
@@ -231,13 +227,10 @@ private void bounceXrefWatcherExecutor() {
231227 }
232228 }
233229
234- private void createLazyForkJoinPool () {
235- lzForkJoinPool = LazilyInstantiate .using (() ->
236- new ForkJoinPool (indexingParallelism , forkJoinPool -> {
237- ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory .newThread (forkJoinPool );
238- thread .setName (OpenGrokThreadFactory .PREFIX + "ForkJoinPool-" + thread .getId ());
239- return thread ;
240- }, null , false ));
230+ private void createIndexWorkExecutor () {
231+ lzIndexWorkExecutor = LazilyInstantiate .using (() ->
232+ Executors .newFixedThreadPool (indexingParallelism ,
233+ new OpenGrokThreadFactory ("index-worker" )));
241234 }
242235
243236 private void createLazyCtagsPool () {
@@ -261,7 +254,7 @@ private void createLazyXrefWatcherExecutor() {
261254 private void createLazyFixedExecutor () {
262255 lzFixedExecutor = LazilyInstantiate .using (() ->
263256 Executors .newFixedThreadPool (indexingParallelism ,
264- new OpenGrokThreadFactory ("index-worker " )));
257+ new OpenGrokThreadFactory ("index-db " )));
265258 }
266259
267260 private void createLazyHistoryExecutor () {
0 commit comments