Skip to content

Commit 992ff29

Browse files
committed
Better name for worker class running scheduled actions
1 parent 387c765 commit 992ff29

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

rxjava-core/src/main/java/rx/schedulers/CachedThreadScheduler.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636

3737
private static final class CachedWorkerPool {
3838
private final long keepAliveTime;
39-
private final ConcurrentLinkedQueue<PoolWorker> expiringQueue;
39+
private final ConcurrentLinkedQueue<ThreadWorker> expiringWorkerQueue;
4040
private final ScheduledExecutorService evictExpiredWorkerExecutor;
4141

4242
CachedWorkerPool(long keepAliveTime, TimeUnit unit) {
4343
this.keepAliveTime = unit.toNanos(keepAliveTime);
44-
this.expiringQueue = new ConcurrentLinkedQueue<PoolWorker>();
44+
this.expiringWorkerQueue = new ConcurrentLinkedQueue<ThreadWorker>();
4545

4646
evictExpiredWorkerExecutor = Executors.newScheduledThreadPool(1, EVICTOR_THREAD_FACTORY);
4747
evictExpiredWorkerExecutor.scheduleWithFixedDelay(
@@ -58,35 +58,35 @@ public void run() {
5858
60L, TimeUnit.SECONDS
5959
);
6060

61-
PoolWorker get() {
62-
while (!expiringQueue.isEmpty()) {
63-
PoolWorker poolWorker = expiringQueue.poll();
64-
if (poolWorker != null) {
65-
return poolWorker;
61+
ThreadWorker get() {
62+
while (!expiringWorkerQueue.isEmpty()) {
63+
ThreadWorker threadWorker = expiringWorkerQueue.poll();
64+
if (threadWorker != null) {
65+
return threadWorker;
6666
}
6767
}
6868

6969
// No cached worker found, so create a new one.
70-
return new PoolWorker(WORKER_THREAD_FACTORY);
70+
return new ThreadWorker(WORKER_THREAD_FACTORY);
7171
}
7272

73-
void release(PoolWorker poolWorker) {
73+
void release(ThreadWorker threadWorker) {
7474
// Refresh expire time before putting worker back in pool
75-
poolWorker.setExpirationTime(now() + keepAliveTime);
75+
threadWorker.setExpirationTime(now() + keepAliveTime);
7676

77-
expiringQueue.add(poolWorker);
77+
expiringWorkerQueue.offer(threadWorker);
7878
}
7979

8080
void evictExpiredWorkers() {
81-
if (!expiringQueue.isEmpty()) {
81+
if (!expiringWorkerQueue.isEmpty()) {
8282
long currentTimestamp = now();
8383

84-
Iterator<PoolWorker> poolWorkerIterator = expiringQueue.iterator();
85-
while (poolWorkerIterator.hasNext()) {
86-
PoolWorker poolWorker = poolWorkerIterator.next();
87-
if (poolWorker.getExpirationTime() <= currentTimestamp) {
88-
poolWorkerIterator.remove();
89-
poolWorker.unsubscribe();
84+
Iterator<ThreadWorker> threadWorkerIterator = expiringWorkerQueue.iterator();
85+
while (threadWorkerIterator.hasNext()) {
86+
ThreadWorker threadWorker = threadWorkerIterator.next();
87+
if (threadWorker.getExpirationTime() <= currentTimestamp) {
88+
threadWorkerIterator.remove();
89+
threadWorker.unsubscribe();
9090
} else {
9191
// Queue is ordered with the worker that will expire first in the beginning, so when we
9292
// find a non-expired worker we can stop evicting.
@@ -108,20 +108,20 @@ public Worker createWorker() {
108108

109109
private static class EventLoopWorker extends Scheduler.Worker {
110110
private final CompositeSubscription innerSubscription = new CompositeSubscription();
111-
private final PoolWorker poolWorker;
111+
private final ThreadWorker threadWorker;
112112
volatile int once;
113113
static final AtomicIntegerFieldUpdater<EventLoopWorker> ONCE_UPDATER
114114
= AtomicIntegerFieldUpdater.newUpdater(EventLoopWorker.class, "once");
115115

116-
EventLoopWorker(PoolWorker poolWorker) {
117-
this.poolWorker = poolWorker;
116+
EventLoopWorker(ThreadWorker threadWorker) {
117+
this.threadWorker = threadWorker;
118118
}
119119

120120
@Override
121121
public void unsubscribe() {
122122
if (ONCE_UPDATER.compareAndSet(this, 0, 1)) {
123123
// unsubscribe should be idempotent, so only do this once
124-
CachedWorkerPool.INSTANCE.release(poolWorker);
124+
CachedWorkerPool.INSTANCE.release(threadWorker);
125125
}
126126
innerSubscription.unsubscribe();
127127
}
@@ -143,17 +143,17 @@ public Subscription schedule(Action0 action, long delayTime, TimeUnit unit) {
143143
return Subscriptions.empty();
144144
}
145145

146-
NewThreadScheduler.NewThreadWorker.ScheduledAction s = poolWorker.scheduleActual(action, delayTime, unit);
146+
NewThreadScheduler.NewThreadWorker.ScheduledAction s = threadWorker.scheduleActual(action, delayTime, unit);
147147
innerSubscription.add(s);
148148
s.addParent(innerSubscription);
149149
return s;
150150
}
151151
}
152152

153-
private static final class PoolWorker extends NewThreadScheduler.NewThreadWorker {
153+
private static final class ThreadWorker extends NewThreadScheduler.NewThreadWorker {
154154
private long expirationTime;
155155

156-
PoolWorker(ThreadFactory threadFactory) {
156+
ThreadWorker(ThreadFactory threadFactory) {
157157
super(threadFactory);
158158
this.expirationTime = 0L;
159159
}

0 commit comments

Comments
 (0)