Skip to content

Commit 31b41f8

Browse files
authored
2.x: fix periodic scheduler purging config not honored (#5441)
1 parent 39e5d91 commit 31b41f8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ private SchedulerPoolFactory() {
5757
* Starts the purge thread if not already started.
5858
*/
5959
public static void start() {
60+
if (!PURGE_ENABLED) {
61+
return;
62+
}
6063
for (;;) {
6164
ScheduledExecutorService curr = PURGE_THREAD.get();
6265
if (curr != null && !curr.isShutdown()) {
@@ -78,7 +81,10 @@ public static void start() {
7881
* Stops the purge thread.
7982
*/
8083
public static void shutdown() {
81-
PURGE_THREAD.get().shutdownNow();
84+
ScheduledExecutorService exec = PURGE_THREAD.get();
85+
if (exec != null) {
86+
exec.shutdownNow();
87+
}
8288
POOLS.clear();
8389
}
8490

@@ -90,10 +96,10 @@ public static void shutdown() {
9096

9197
if (properties.containsKey(PURGE_ENABLED_KEY)) {
9298
purgeEnable = Boolean.getBoolean(PURGE_ENABLED_KEY);
99+
}
93100

94-
if (purgeEnable && properties.containsKey(PURGE_PERIOD_SECONDS_KEY)) {
95-
purgePeriod = Integer.getInteger(PURGE_PERIOD_SECONDS_KEY, purgePeriod);
96-
}
101+
if (purgeEnable && properties.containsKey(PURGE_PERIOD_SECONDS_KEY)) {
102+
purgePeriod = Integer.getInteger(PURGE_PERIOD_SECONDS_KEY, purgePeriod);
97103
}
98104

99105
PURGE_ENABLED = purgeEnable;
@@ -109,7 +115,7 @@ public static void shutdown() {
109115
*/
110116
public static ScheduledExecutorService create(ThreadFactory factory) {
111117
final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1, factory);
112-
if (exec instanceof ScheduledThreadPoolExecutor) {
118+
if (PURGE_ENABLED && exec instanceof ScheduledThreadPoolExecutor) {
113119
ScheduledThreadPoolExecutor e = (ScheduledThreadPoolExecutor) exec;
114120
POOLS.put(e, exec);
115121
}

0 commit comments

Comments
 (0)