File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
src/main/java/rx/schedulers Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 3131 /** Manages a fixed number of workers. */
3232 private static final String THREAD_NAME_PREFIX = "RxComputationThreadPool-" ;
3333 private static final RxThreadFactory THREAD_FACTORY = new RxThreadFactory (THREAD_NAME_PREFIX );
34-
34+ /**
35+ * Key to setting the maximum number of computation scheduler threads.
36+ * Zero or less is interpreted as use available. Capped by available.
37+ */
38+ static final String KEY_MAX_THREADS = "rx.scheduler.max-computation-threads" ;
39+ /** The maximum number of computation scheduler threads. */
40+ static final int MAX_THREADS ;
41+ static {
42+ int maxThreads = Integer .getInteger (KEY_MAX_THREADS , 0 );
43+ int ncpu = Runtime .getRuntime ().availableProcessors ();
44+ int max ;
45+ if (maxThreads <= 0 || maxThreads > ncpu ) {
46+ max = ncpu ;
47+ } else {
48+ max = maxThreads ;
49+ }
50+ MAX_THREADS = max ;
51+ }
3552 static final class FixedSchedulerPool {
3653 final int cores ;
3754
@@ -40,7 +57,7 @@ static final class FixedSchedulerPool {
4057
4158 FixedSchedulerPool () {
4259 // initialize event loops
43- this .cores = Runtime . getRuntime (). availableProcessors () ;
60+ this .cores = MAX_THREADS ;
4461 this .eventLoops = new PoolWorker [cores ];
4562 for (int i = 0 ; i < cores ; i ++) {
4663 this .eventLoops [i ] = new PoolWorker (THREAD_FACTORY );
You can’t perform that action at this time.
0 commit comments