Skip to content

Commit 6478312

Browse files
pawellozinskiakarnokd
authored andcommitted
2.x: Expose the Keep-Alive value of the IO Scheduler as System property. (#6279) (#6287)
1 parent 3281b02 commit 6478312

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/java/io/reactivex/internal/schedulers/IoScheduler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public final class IoScheduler extends Scheduler {
3434
private static final String EVICTOR_THREAD_NAME_PREFIX = "RxCachedWorkerPoolEvictor";
3535
static final RxThreadFactory EVICTOR_THREAD_FACTORY;
3636

37-
private static final long KEEP_ALIVE_TIME = 60;
37+
/** The name of the system property for setting the keep-alive time (in seconds) for this Scheduler workers. */
38+
private static final String KEY_KEEP_ALIVE_TIME = "rx2.io-keep-alive-time";
39+
public static final long KEEP_ALIVE_TIME_DEFAULT = 60;
40+
41+
private static final long KEEP_ALIVE_TIME;
3842
private static final TimeUnit KEEP_ALIVE_UNIT = TimeUnit.SECONDS;
3943

4044
static final ThreadWorker SHUTDOWN_THREAD_WORKER;
@@ -45,7 +49,10 @@ public final class IoScheduler extends Scheduler {
4549
private static final String KEY_IO_PRIORITY = "rx2.io-priority";
4650

4751
static final CachedWorkerPool NONE;
52+
4853
static {
54+
KEEP_ALIVE_TIME = Long.getLong(KEY_KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_DEFAULT);
55+
4956
SHUTDOWN_THREAD_WORKER = new ThreadWorker(new RxThreadFactory("RxCachedThreadSchedulerShutdown"));
5057
SHUTDOWN_THREAD_WORKER.dispose();
5158

src/main/java/io/reactivex/schedulers/Schedulers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* <p>
3030
* <strong>Supported system properties ({@code System.getProperty()}):</strong>
3131
* <ul>
32+
* <li>{@code rx2.io-keep-alive-time} (long): sets the keep-alive time of the {@link #io()} Scheduler workers, default is {@link IoScheduler#KEEP_ALIVE_TIME_DEFAULT}</li>
3233
* <li>{@code rx2.io-priority} (int): sets the thread priority of the {@link #io()} Scheduler, default is {@link Thread#NORM_PRIORITY}</li>
3334
* <li>{@code rx2.computation-threads} (int): sets the number of threads in the {@link #computation()} Scheduler, default is the number of available CPUs</li>
3435
* <li>{@code rx2.computation-priority} (int): sets the thread priority of the {@link #computation()} Scheduler, default is {@link Thread#NORM_PRIORITY}</li>
@@ -155,6 +156,7 @@ public static Scheduler computation() {
155156
* before the {@link Schedulers} class is referenced in your code.
156157
* <p><strong>Supported system properties ({@code System.getProperty()}):</strong>
157158
* <ul>
159+
* <li>{@code rx2.io-keep-alive-time} (long): sets the keep-alive time of the {@link #io()} Scheduler workers, default is {@link IoScheduler#KEEP_ALIVE_TIME_DEFAULT}</li>
158160
* <li>{@code rx2.io-priority} (int): sets the thread priority of the {@link #io()} Scheduler, default is {@link Thread#NORM_PRIORITY}</li>
159161
* </ul>
160162
* <p>

0 commit comments

Comments
 (0)