85 |
|
|
86 |
|
|
87 |
|
public long getDelay(TimeUnit unit) { |
88 |
< |
return unit.convert(time - System.nanoTime(), |
88 |
> |
long d = unit.convert(time - System.nanoTime(), |
89 |
|
TimeUnit.NANOSECONDS); |
90 |
+ |
return d; |
91 |
|
} |
92 |
|
|
93 |
|
public int compareTo(Object other) { |
180 |
|
* An annoying wrapper class to convince generics compiler to |
181 |
|
* use a DelayQueue<DelayedTask> as a BlockingQueue<Runnable> |
182 |
|
*/ |
183 |
< |
private static class DelayedWorkQueue extends AbstractQueue<Runnable> implements BlockingQueue<Runnable> { |
183 |
> |
private static class DelayedWorkQueue extends AbstractCollection<Runnable> implements BlockingQueue<Runnable> { |
184 |
|
private final DelayQueue<DelayedTask> dq = new DelayQueue<DelayedTask>(); |
185 |
|
public Runnable poll() { return dq.poll(); } |
186 |
|
public Runnable peek() { return dq.peek(); } |
188 |
|
public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException { |
189 |
|
return dq.poll(timeout, unit); |
190 |
|
} |
191 |
+ |
|
192 |
+ |
public boolean add(Runnable x) { return dq.add((DelayedTask)x); } |
193 |
|
public boolean offer(Runnable x) { return dq.offer((DelayedTask)x); } |
194 |
|
public void put(Runnable x) throws InterruptedException { |
195 |
|
dq.put((DelayedTask)x); |
197 |
|
public boolean offer(Runnable x, long timeout, TimeUnit unit) throws InterruptedException { |
198 |
|
return dq.offer((DelayedTask)x, timeout, unit); |
199 |
|
} |
200 |
+ |
|
201 |
+ |
public Runnable remove() { return dq.remove(); } |
202 |
+ |
public Runnable element() { return dq.element(); } |
203 |
+ |
public void clear() { dq.clear(); } |
204 |
+ |
|
205 |
|
public int remainingCapacity() { return dq.remainingCapacity(); } |
206 |
|
public boolean remove(Object x) { return dq.remove(x); } |
207 |
|
public boolean contains(Object x) { return dq.contains(x); } |
226 |
|
public ScheduledExecutor(int corePoolSize) { |
227 |
|
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS, |
228 |
|
new DelayedWorkQueue()); |
229 |
+ |
prestartCoreThreads(); |
230 |
|
} |
231 |
|
|
232 |
|
/** |
241 |
|
ThreadFactory threadFactory) { |
242 |
|
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS, |
243 |
|
new DelayedWorkQueue(), threadFactory); |
244 |
+ |
prestartCoreThreads(); |
245 |
|
} |
246 |
|
|
247 |
|
/** |
256 |
|
RejectedExecutionHandler handler) { |
257 |
|
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS, |
258 |
|
new DelayedWorkQueue(), handler); |
259 |
+ |
prestartCoreThreads(); |
260 |
|
} |
261 |
|
|
262 |
|
/** |
274 |
|
RejectedExecutionHandler handler) { |
275 |
|
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS, |
276 |
|
new DelayedWorkQueue(), threadFactory, handler); |
277 |
+ |
prestartCoreThreads(); |
278 |
|
} |
279 |
|
|
280 |
|
/** |
464 |
|
if (next == null) |
465 |
|
return; |
466 |
|
try { |
467 |
< |
super.execute(next); |
467 |
> |
execute(next); |
468 |
|
} |
469 |
|
catch(RejectedExecutionException ex) { |
470 |
|
// lost race to detect shutdown; ignore |