247 |
|
new AbortPolicy(); |
248 |
|
|
249 |
|
/** |
250 |
+ |
* Invoke the rejected execution handler for the give command. |
251 |
+ |
*/ |
252 |
+ |
void reject(Runnable command) { |
253 |
+ |
handler.rejectedExecution(command, this); |
254 |
+ |
} |
255 |
+ |
|
256 |
+ |
|
257 |
+ |
/** |
258 |
|
* Create and return a new thread running firstTask as its first |
259 |
|
* task. Call only while holding mainLock |
260 |
|
* @param firstTask the task the new thread should run first (or |
279 |
|
* null if none) |
280 |
|
* @return true if successful. |
281 |
|
*/ |
282 |
< |
private boolean addIfUnderCorePoolSize(Runnable firstTask) { |
282 |
> |
// non-private; accessible to ScheduledExecutor |
283 |
> |
boolean addIfUnderCorePoolSize(Runnable firstTask) { |
284 |
|
Thread t = null; |
285 |
|
mainLock.lock(); |
286 |
|
try { |
297 |
|
} |
298 |
|
|
299 |
|
/** |
291 |
– |
* Eagerly (vs by default lazily) start all core threads. |
292 |
– |
*/ |
293 |
– |
void prestartCoreThreads() { |
294 |
– |
while (addIfUnderCorePoolSize(null)) { |
295 |
– |
} |
296 |
– |
} |
297 |
– |
|
298 |
– |
|
299 |
– |
/** |
300 |
|
* Create and start a new thread only if less than maximumPoolSize |
301 |
|
* threads are running. The new thread runs as its first task the |
302 |
|
* next task in queue, or if there is none, the given task. |
681 |
|
public void execute(Runnable command) { |
682 |
|
for (;;) { |
683 |
|
if (shutdownStatus != NOT_SHUTDOWN) { |
684 |
< |
handler.rejectedExecution(command, this); |
684 |
> |
reject(command); |
685 |
|
return; |
686 |
|
} |
687 |
|
if (poolSize < corePoolSize && addIfUnderCorePoolSize(command)) |
692 |
|
if (r == command) |
693 |
|
return; |
694 |
|
if (r == null) { |
695 |
< |
handler.rejectedExecution(command, this); |
695 |
> |
reject(command); |
696 |
|
return; |
697 |
|
} |
698 |
|
// else retry |