25
25
26
26
import java .util .concurrent .ExecutorService ;
27
27
import java .util .concurrent .Executors ;
28
- import java .util .concurrent .ForkJoinPool ;
29
- import java .util .concurrent .ForkJoinWorkerThread ;
30
28
import java .util .concurrent .ScheduledThreadPoolExecutor ;
31
29
32
30
import org .opengrok .indexer .analysis .Ctags ;
38
36
import org .opengrok .indexer .util .ObjectFactory ;
39
37
import org .opengrok .indexer .util .ObjectPool ;
40
38
41
- import static java .util .concurrent .ForkJoinPool .defaultForkJoinWorkerThreadFactory ;
42
-
43
39
/**
44
40
* Represents a container for executors that enable parallelism for indexing
45
41
* across projects and repositories and also within any {@link IndexDatabase}
46
42
* instance -- with global limits for all execution.
47
43
* <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
49
45
* {@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
54
50
* history, and for watching the {@link Ctags} instances for timing purposes.
55
51
*/
56
52
public class IndexerParallelizer implements AutoCloseable {
57
53
58
54
private final RuntimeEnvironment env ;
59
55
private final int indexingParallelism ;
60
56
61
- private LazilyInstantiate <ForkJoinPool > lzForkJoinPool ;
57
+ private LazilyInstantiate <ExecutorService > lzIndexWorkExecutor ;
62
58
private LazilyInstantiate <ObjectPool <Ctags >> lzCtagsPool ;
63
59
private LazilyInstantiate <ExecutorService > lzFixedExecutor ;
64
60
private LazilyInstantiate <ExecutorService > lzHistoryExecutor ;
@@ -82,7 +78,7 @@ public IndexerParallelizer(RuntimeEnvironment env) {
82
78
*/
83
79
this .indexingParallelism = env .getIndexingParallelism ();
84
80
85
- createLazyForkJoinPool ();
81
+ createIndexWorkExecutor ();
86
82
createLazyCtagsPool ();
87
83
createLazyFixedExecutor ();
88
84
createLazyHistoryExecutor ();
@@ -99,10 +95,10 @@ public ExecutorService getFixedExecutor() {
99
95
}
100
96
101
97
/**
102
- * @return the forkJoinPool
98
+ * @return the executor used for individual file processing in the 2nd stage of indexing
103
99
*/
104
- public ForkJoinPool getForkJoinPool () {
105
- return lzForkJoinPool .get ();
100
+ public ExecutorService getIndexWorkExecutor () {
101
+ return lzIndexWorkExecutor .get ();
106
102
}
107
103
108
104
/**
@@ -166,7 +162,7 @@ public void close() {
166
162
* call this method satisfactorily too.
167
163
*/
168
164
public void bounce () {
169
- bounceForkJoinPool ();
165
+ bounceIndexWorkExecutor ();
170
166
bounceFixedExecutor ();
171
167
bounceCtagsPool ();
172
168
bounceHistoryExecutor ();
@@ -175,11 +171,11 @@ public void bounce() {
175
171
bounceXrefWatcherExecutor ();
176
172
}
177
173
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 ();
183
179
}
184
180
}
185
181
@@ -231,13 +227,10 @@ private void bounceXrefWatcherExecutor() {
231
227
}
232
228
}
233
229
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" )));
241
234
}
242
235
243
236
private void createLazyCtagsPool () {
@@ -261,7 +254,7 @@ private void createLazyXrefWatcherExecutor() {
261
254
private void createLazyFixedExecutor () {
262
255
lzFixedExecutor = LazilyInstantiate .using (() ->
263
256
Executors .newFixedThreadPool (indexingParallelism ,
264
- new OpenGrokThreadFactory ("index-worker " )));
257
+ new OpenGrokThreadFactory ("index-db " )));
265
258
}
266
259
267
260
private void createLazyHistoryExecutor () {
0 commit comments