@@ -48,7 +48,7 @@ private static Schedulers getInstance() {
48
48
if (INSTANCE .compareAndSet (null , current )) {
49
49
return current ;
50
50
} else {
51
- shutdown ();
51
+ current . shutdownInstance ();
52
52
}
53
53
}
54
54
}
@@ -168,8 +168,10 @@ public static Scheduler from(Executor executor) {
168
168
*/
169
169
@ Experimental
170
170
public static void reset () {
171
- shutdown ();
172
- INSTANCE .set (null );
171
+ Schedulers s = INSTANCE .getAndSet (null );
172
+ if (s != null ) {
173
+ s .shutdownInstance ();
174
+ }
173
175
}
174
176
175
177
/**
@@ -178,16 +180,10 @@ public static void reset() {
178
180
*/
179
181
/* public test only */ static void start () {
180
182
Schedulers s = getInstance ();
183
+
184
+ s .startInstance ();
185
+
181
186
synchronized (s ) {
182
- if (s .computationScheduler instanceof SchedulerLifecycle ) {
183
- ((SchedulerLifecycle ) s .computationScheduler ).start ();
184
- }
185
- if (s .ioScheduler instanceof SchedulerLifecycle ) {
186
- ((SchedulerLifecycle ) s .ioScheduler ).start ();
187
- }
188
- if (s .newThreadScheduler instanceof SchedulerLifecycle ) {
189
- ((SchedulerLifecycle ) s .newThreadScheduler ).start ();
190
- }
191
187
GenericScheduledExecutorService .INSTANCE .start ();
192
188
193
189
RxRingBuffer .SPSC_POOL .start ();
@@ -201,22 +197,44 @@ public static void reset() {
201
197
*/
202
198
public static void shutdown () {
203
199
Schedulers s = getInstance ();
204
- synchronized (s ) {
205
- if (s .computationScheduler instanceof SchedulerLifecycle ) {
206
- ((SchedulerLifecycle ) s .computationScheduler ).shutdown ();
207
- }
208
- if (s .ioScheduler instanceof SchedulerLifecycle ) {
209
- ((SchedulerLifecycle ) s .ioScheduler ).shutdown ();
210
- }
211
- if (s .newThreadScheduler instanceof SchedulerLifecycle ) {
212
- ((SchedulerLifecycle ) s .newThreadScheduler ).shutdown ();
213
- }
200
+ s .shutdownInstance ();
214
201
202
+ synchronized (s ) {
215
203
GenericScheduledExecutorService .INSTANCE .shutdown ();
216
-
204
+
217
205
RxRingBuffer .SPSC_POOL .shutdown ();
218
206
219
207
RxRingBuffer .SPMC_POOL .shutdown ();
220
208
}
221
209
}
210
+
211
+ /**
212
+ * Start the instance-specific schedulers.
213
+ */
214
+ synchronized void startInstance () {
215
+ if (computationScheduler instanceof SchedulerLifecycle ) {
216
+ ((SchedulerLifecycle ) computationScheduler ).start ();
217
+ }
218
+ if (ioScheduler instanceof SchedulerLifecycle ) {
219
+ ((SchedulerLifecycle ) ioScheduler ).start ();
220
+ }
221
+ if (newThreadScheduler instanceof SchedulerLifecycle ) {
222
+ ((SchedulerLifecycle ) newThreadScheduler ).start ();
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Start the instance-specific schedulers.
228
+ */
229
+ synchronized void shutdownInstance () {
230
+ if (computationScheduler instanceof SchedulerLifecycle ) {
231
+ ((SchedulerLifecycle ) computationScheduler ).shutdown ();
232
+ }
233
+ if (ioScheduler instanceof SchedulerLifecycle ) {
234
+ ((SchedulerLifecycle ) ioScheduler ).shutdown ();
235
+ }
236
+ if (newThreadScheduler instanceof SchedulerLifecycle ) {
237
+ ((SchedulerLifecycle ) newThreadScheduler ).shutdown ();
238
+ }
239
+ }
222
240
}
0 commit comments