Index executors: Use directExecutor for negative thread values

This will make it easier to test index-related logic in tests. We still
use 0 as a default way of setting the JVM threads.

Change-Id: If186a23ee4e79c49306bf9f286a24841d99e6531
This commit is contained in:
Patrick Hiesel
2018-07-04 10:54:26 +02:00
parent 15e6a73d94
commit bdbee9cf8e
3 changed files with 16 additions and 11 deletions

View File

@@ -104,7 +104,7 @@ public class IndexModule extends LifecycleModule {
public IndexModule(
ListeningExecutorService interactiveExecutor, ListeningExecutorService batchExecutor) {
this.threads = -1;
this.threads = 0;
this.interactiveExecutor = interactiveExecutor;
this.batchExecutor = batchExecutor;
this.closeExecutorsOnShutdown = false;
@@ -211,11 +211,12 @@ public class IndexModule extends LifecycleModule {
return interactiveExecutor;
}
int threads = this.threads;
if (threads <= 0) {
threads = config.getInt("index", null, "threads", 0);
}
if (threads <= 0) {
threads = Runtime.getRuntime().availableProcessors() / 2 + 1;
if (threads < 0) {
return MoreExecutors.newDirectExecutorService();
} else if (threads == 0) {
threads =
config.getInt(
"index", null, "threads", Runtime.getRuntime().availableProcessors() / 2 + 1);
}
return MoreExecutors.listeningDecorator(
workQueue.createQueue(threads, "Index-Interactive", true));
@@ -230,7 +231,9 @@ public class IndexModule extends LifecycleModule {
return batchExecutor;
}
int threads = config.getInt("index", null, "batchThreads", 0);
if (threads <= 0) {
if (threads < 0) {
return MoreExecutors.newDirectExecutorService();
} else if (threads == 0) {
threads = Runtime.getRuntime().availableProcessors();
}
return MoreExecutors.listeningDecorator(workQueue.createQueue(threads, "Index-Batch", true));