Skip to content

Commit 399cbf9

Browse files
Merge pull request #1827 from alexwen/1826_scheduler_termination
CacheThreadScheduler Evictor should Check Removal
2 parents 6f4c27e + 79e4c4e commit 399cbf9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/main/java/rx/schedulers/CachedThreadScheduler.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import rx.subscriptions.CompositeSubscription;
2525
import rx.subscriptions.Subscriptions;
2626

27-
import java.util.Iterator;
2827
import java.util.concurrent.*;
2928
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
3029

@@ -84,12 +83,11 @@ void evictExpiredWorkers() {
8483
if (!expiringWorkerQueue.isEmpty()) {
8584
long currentTimestamp = now();
8685

87-
Iterator<ThreadWorker> threadWorkerIterator = expiringWorkerQueue.iterator();
88-
while (threadWorkerIterator.hasNext()) {
89-
ThreadWorker threadWorker = threadWorkerIterator.next();
86+
for (ThreadWorker threadWorker : expiringWorkerQueue) {
9087
if (threadWorker.getExpirationTime() <= currentTimestamp) {
91-
threadWorkerIterator.remove();
92-
threadWorker.unsubscribe();
88+
if (expiringWorkerQueue.remove(threadWorker)) {
89+
threadWorker.unsubscribe();
90+
}
9391
} else {
9492
// Queue is ordered with the worker that will expire first in the beginning, so when we
9593
// find a non-expired worker we can stop evicting.

0 commit comments

Comments
 (0)