Allow thread pool to be sized with -Dthread_pool_size.

Also use num processors minus one instead of num processors.
This commit is contained in:
Michael Bayne
2018-10-03 08:47:19 -07:00
parent 5499969b2c
commit 0f5622df72
3 changed files with 8 additions and 3 deletions
@@ -1224,7 +1224,7 @@ public class Application
// resources are verified on background threads supplied by the thread pool, and progress // resources are verified on background threads supplied by the thread pool, and progress
// is reported by posting runnable actions to the actions queue which is processed by the // is reported by posting runnable actions to the actions queue which is processed by the
// main (UI) thread // main (UI) thread
Executor exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); Executor exec = Executors.newFixedThreadPool(SysProps.threadPoolSize());
final BlockingQueue<Runnable> actions = new LinkedBlockingQueue<Runnable>(); final BlockingQueue<Runnable> actions = new LinkedBlockingQueue<Runnable>();
final int[] completed = new int[1]; final int[] completed = new int[1];
@@ -56,8 +56,7 @@ public class Digest
throws IOException throws IOException
{ {
// first compute the digests for all the resources in parallel // first compute the digests for all the resources in parallel
ExecutorService exec = Executors.newFixedThreadPool( ExecutorService exec = Executors.newFixedThreadPool(SysProps.threadPoolSize());
Runtime.getRuntime().availableProcessors());
final Map<Resource, String> digests = new ConcurrentHashMap<>(); final Map<Resource, String> digests = new ConcurrentHashMap<>();
final BlockingQueue<Object> completed = new LinkedBlockingQueue<>(); final BlockingQueue<Object> completed = new LinkedBlockingQueue<>();
final int fversion = version; final int fversion = version;
@@ -107,6 +107,12 @@ public class SysProps
return Integer.getInteger("read_timeout", 30); return Integer.getInteger("read_timeout", 30);
} }
/** Returns the number of threads used to perform digesting and verifying operations in
* parallel. Usage: {@code -Dthread_pool_size=N} */
public static int threadPoolSize () {
return Integer.getInteger("thread_pool_size", Runtime.getRuntime().availableProcessors()-1);
}
/** Parses a Java version system property using the supplied regular expression. The numbers /** Parses a Java version system property using the supplied regular expression. The numbers
* extracted from the regexp will be placed in each consecutive hundreds position in the * extracted from the regexp will be placed in each consecutive hundreds position in the
* returned value. * returned value.