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 31
31
/** Manages a fixed number of workers. */
32
32
private static final String THREAD_NAME_PREFIX = "RxComputationThreadPool-" ;
33
33
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
+ }
35
52
static final class FixedSchedulerPool {
36
53
final int cores ;
37
54
@@ -40,7 +57,7 @@ static final class FixedSchedulerPool {
40
57
41
58
FixedSchedulerPool () {
42
59
// initialize event loops
43
- this .cores = Runtime . getRuntime (). availableProcessors () ;
60
+ this .cores = MAX_THREADS ;
44
61
this .eventLoops = new PoolWorker [cores ];
45
62
for (int i = 0 ; i < cores ; i ++) {
46
63
this .eventLoops [i ] = new PoolWorker (THREAD_FACTORY );
You can’t perform that action at this time.
0 commit comments