44 |
|
* A wrapper class that exposes only the ExecutorService and |
45 |
|
* ScheduleExecutor methods of a ScheduledThreadPoolExecutor. |
46 |
|
*/ |
47 |
< |
private static class DelegatedScheduledExecutorService |
48 |
< |
extends DelegatedExecutorService |
49 |
< |
implements ScheduledExecutor { |
50 |
< |
|
47 |
> |
private static class DelegatedScheduledExecutorService |
48 |
> |
extends DelegatedExecutorService implements ScheduledExecutor { |
49 |
|
private final ScheduledExecutor e; |
50 |
|
DelegatedScheduledExecutorService(ScheduledThreadPoolExecutor executor) { |
51 |
|
super(executor); |
173 |
|
new SynchronousQueue<Runnable>(), |
174 |
|
threadFactory)); |
175 |
|
} |
176 |
< |
|
179 |
< |
|
176 |
> |
|
177 |
|
/** |
178 |
|
* Creates a thread pool that can schedule commands to run after a |
179 |
|
* given delay, or to execute periodically. |
181 |
|
* an <tt>ExecutorService</tt>. |
182 |
|
*/ |
183 |
|
public static ScheduledExecutor newScheduledThreadPool() { |
184 |
< |
return newScheduledThreadPool(0); |
184 |
> |
return newScheduledThreadPool(1); |
185 |
|
} |
186 |
|
|
190 |
– |
|
187 |
|
/** |
188 |
|
* Creates a thread pool that can schedule commands to run after a |
189 |
|
* given delay, or to execute periodically. |
193 |
|
* an <tt>ExecutorService</tt>. |
194 |
|
*/ |
195 |
|
public static ScheduledExecutor newScheduledThreadPool(int corePoolSize) { |
196 |
< |
return newScheduledThreadPool(corePoolSize, null); |
196 |
> |
return new DelegatedScheduledExecutorService |
197 |
> |
(new ScheduledThreadPoolExecutor(corePoolSize)); |
198 |
|
} |
199 |
|
|
203 |
– |
|
200 |
|
/** |
201 |
|
* Creates a thread pool that can schedule commands to run after a |
202 |
|
* given delay, or to execute periodically. |
209 |
|
*/ |
210 |
|
public static ScheduledExecutor newScheduledThreadPool(int corePoolSize, |
211 |
|
ThreadFactory threadFactory) { |
212 |
< |
return newScheduledThreadPool(corePoolSize, threadFactory, false, false); |
213 |
< |
} |
218 |
< |
|
219 |
< |
|
220 |
< |
/** |
221 |
< |
* Creates a thread pool that can schedule commands to run after a |
222 |
< |
* given delay, or to execute periodically. |
223 |
< |
* @param corePoolSize the number of threads to keep in the pool, |
224 |
< |
* even if they are idle. |
225 |
< |
* @param threadFactory the factory to use when the executor |
226 |
< |
* creates a new thread. |
227 |
< |
* @param continueExistingPeriodicTasksAfterShutdown whether to |
228 |
< |
* continue executing existing periodic tasks even when the returned |
229 |
< |
* executor has been <tt>shutdown</tt>. |
230 |
< |
* @param executeExistingDelayedTasksAfterShutdown whether to |
231 |
< |
* continue executing existing delayed tasks even when the returned |
232 |
< |
* executor has been <tt>shutdown</tt>. |
233 |
< |
* @return a <tt>ScheduledExecutor</tt> that may safely be cast to |
234 |
< |
* an <tt>ExecutorService</tt>. |
235 |
< |
*/ |
236 |
< |
public static ScheduledExecutor newScheduledThreadPool( |
237 |
< |
int corePoolSize, |
238 |
< |
ThreadFactory threadFactory, |
239 |
< |
boolean continueExistingPeriodicTasksAfterShutdown, |
240 |
< |
boolean executeExistingDelayedTasksAfterShutdown) { |
241 |
< |
|
242 |
< |
ScheduledThreadPoolExecutor stpe = threadFactory == null ? |
243 |
< |
new ScheduledThreadPoolExecutor(corePoolSize) : |
244 |
< |
new ScheduledThreadPoolExecutor(corePoolSize, threadFactory); |
245 |
< |
|
246 |
< |
stpe.setContinueExistingPeriodicTasksAfterShutdownPolicy( |
247 |
< |
continueExistingPeriodicTasksAfterShutdown); |
248 |
< |
|
249 |
< |
stpe.setExecuteExistingDelayedTasksAfterShutdownPolicy( |
250 |
< |
executeExistingDelayedTasksAfterShutdown); |
251 |
< |
|
252 |
< |
return new DelegatedScheduledExecutorService(stpe); |
212 |
> |
return new DelegatedScheduledExecutorService |
213 |
> |
(new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)); |
214 |
|
} |
254 |
– |
|
215 |
|
|
216 |
|
/** |
217 |
|
* Executes a Runnable task and returns a Future representing that |