1 /*
2  * Written by Doug Lea with assistance from members of JCP JSR-166
3  * Expert Group and released to the public domain, as explained at
4  * http://creativecommons.org/publicdomain/zero/1.0/
5  */
6 
7 package java.util.concurrent;
8 import java.util.*;
9 import java.util.concurrent.atomic.AtomicInteger;
10 import java.security.AccessControlContext;
11 import java.security.AccessController;
12 import java.security.PrivilegedAction;
13 import java.security.PrivilegedExceptionAction;
14 import java.security.PrivilegedActionException;
15 
16 // BEGIN android-note
17 // removed security manager docs
18 // END android-note
19 /**
20  * Factory and utility methods for {@link Executor}, {@link
21  * ExecutorService}, {@link ScheduledExecutorService}, {@link
22  * ThreadFactory}, and {@link Callable} classes defined in this
23  * package. This class supports the following kinds of methods:
24  *
25  * <ul>
26  *   <li> Methods that create and return an {@link ExecutorService}
27  *        set up with commonly useful configuration settings.
28  *   <li> Methods that create and return a {@link ScheduledExecutorService}
29  *        set up with commonly useful configuration settings.
30  *   <li> Methods that create and return a "wrapped" ExecutorService, that
31  *        disables reconfiguration by making implementation-specific methods
32  *        inaccessible.
33  *   <li> Methods that create and return a {@link ThreadFactory}
34  *        that sets newly created threads to a known state.
35  *   <li> Methods that create and return a {@link Callable}
36  *        out of other closure-like forms, so they can be used
37  *        in execution methods requiring {@code Callable}.
38  * </ul>
39  *
40  * @since 1.5
41  * @author Doug Lea
42  */
43 public class Executors {
44 
45     /**
46      * Creates a thread pool that reuses a fixed number of threads
47      * operating off a shared unbounded queue.  At any point, at most
48      * {@code nThreads} threads will be active processing tasks.
49      * If additional tasks are submitted when all threads are active,
50      * they will wait in the queue until a thread is available.
51      * If any thread terminates due to a failure during execution
52      * prior to shutdown, a new one will take its place if needed to
53      * execute subsequent tasks.  The threads in the pool will exist
54      * until it is explicitly {@link ExecutorService#shutdown shutdown}.
55      *
56      * @param nThreads the number of threads in the pool
57      * @return the newly created thread pool
58      * @throws IllegalArgumentException if {@code nThreads <= 0}
59      */
newFixedThreadPool(int nThreads)60     public static ExecutorService newFixedThreadPool(int nThreads) {
61         return new ThreadPoolExecutor(nThreads, nThreads,
62                                       0L, TimeUnit.MILLISECONDS,
63                                       new LinkedBlockingQueue<Runnable>());
64     }
65 
66     /**
67      * Creates a thread pool that maintains enough threads to support
68      * the given parallelism level, and may use multiple queues to
69      * reduce contention. The parallelism level corresponds to the
70      * maximum number of threads actively engaged in, or available to
71      * engage in, task processing. The actual number of threads may
72      * grow and shrink dynamically. A work-stealing pool makes no
73      * guarantees about the order in which submitted tasks are
74      * executed.
75      *
76      * @param parallelism the targeted parallelism level
77      * @return the newly created thread pool
78      * @throws IllegalArgumentException if {@code parallelism <= 0}
79      * @since 1.8
80      * @hide
81      */
newWorkStealingPool(int parallelism)82     public static ExecutorService newWorkStealingPool(int parallelism) {
83         return new ForkJoinPool
84             (parallelism,
85              ForkJoinPool.defaultForkJoinWorkerThreadFactory,
86              null, true);
87     }
88 
89     /**
90      * Creates a work-stealing thread pool using all
91      * {@link Runtime#availableProcessors available processors}
92      * as its target parallelism level.
93      * @return the newly created thread pool
94      * @since 1.8
95      * @hide
96      */
newWorkStealingPool()97     public static ExecutorService newWorkStealingPool() {
98         return new ForkJoinPool
99             (Runtime.getRuntime().availableProcessors(),
100              ForkJoinPool.defaultForkJoinWorkerThreadFactory,
101              null, true);
102     }
103 
104     /**
105      * Creates a thread pool that reuses a fixed number of threads
106      * operating off a shared unbounded queue, using the provided
107      * ThreadFactory to create new threads when needed.  At any point,
108      * at most {@code nThreads} threads will be active processing
109      * tasks.  If additional tasks are submitted when all threads are
110      * active, they will wait in the queue until a thread is
111      * available.  If any thread terminates due to a failure during
112      * execution prior to shutdown, a new one will take its place if
113      * needed to execute subsequent tasks.  The threads in the pool will
114      * exist until it is explicitly {@link ExecutorService#shutdown
115      * shutdown}.
116      *
117      * @param nThreads the number of threads in the pool
118      * @param threadFactory the factory to use when creating new threads
119      * @return the newly created thread pool
120      * @throws NullPointerException if threadFactory is null
121      * @throws IllegalArgumentException if {@code nThreads <= 0}
122      */
newFixedThreadPool(int nThreads, ThreadFactory threadFactory)123     public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) {
124         return new ThreadPoolExecutor(nThreads, nThreads,
125                                       0L, TimeUnit.MILLISECONDS,
126                                       new LinkedBlockingQueue<Runnable>(),
127                                       threadFactory);
128     }
129 
130     /**
131      * Creates an Executor that uses a single worker thread operating
132      * off an unbounded queue. (Note however that if this single
133      * thread terminates due to a failure during execution prior to
134      * shutdown, a new one will take its place if needed to execute
135      * subsequent tasks.)  Tasks are guaranteed to execute
136      * sequentially, and no more than one task will be active at any
137      * given time. Unlike the otherwise equivalent
138      * {@code newFixedThreadPool(1)} the returned executor is
139      * guaranteed not to be reconfigurable to use additional threads.
140      *
141      * @return the newly created single-threaded Executor
142      */
newSingleThreadExecutor()143     public static ExecutorService newSingleThreadExecutor() {
144         return new FinalizableDelegatedExecutorService
145             (new ThreadPoolExecutor(1, 1,
146                                     0L, TimeUnit.MILLISECONDS,
147                                     new LinkedBlockingQueue<Runnable>()));
148     }
149 
150     /**
151      * Creates an Executor that uses a single worker thread operating
152      * off an unbounded queue, and uses the provided ThreadFactory to
153      * create a new thread when needed. Unlike the otherwise
154      * equivalent {@code newFixedThreadPool(1, threadFactory)} the
155      * returned executor is guaranteed not to be reconfigurable to use
156      * additional threads.
157      *
158      * @param threadFactory the factory to use when creating new
159      * threads
160      *
161      * @return the newly created single-threaded Executor
162      * @throws NullPointerException if threadFactory is null
163      */
newSingleThreadExecutor(ThreadFactory threadFactory)164     public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory) {
165         return new FinalizableDelegatedExecutorService
166             (new ThreadPoolExecutor(1, 1,
167                                     0L, TimeUnit.MILLISECONDS,
168                                     new LinkedBlockingQueue<Runnable>(),
169                                     threadFactory));
170     }
171 
172     /**
173      * Creates a thread pool that creates new threads as needed, but
174      * will reuse previously constructed threads when they are
175      * available.  These pools will typically improve the performance
176      * of programs that execute many short-lived asynchronous tasks.
177      * Calls to {@code execute} will reuse previously constructed
178      * threads if available. If no existing thread is available, a new
179      * thread will be created and added to the pool. Threads that have
180      * not been used for sixty seconds are terminated and removed from
181      * the cache. Thus, a pool that remains idle for long enough will
182      * not consume any resources. Note that pools with similar
183      * properties but different details (for example, timeout parameters)
184      * may be created using {@link ThreadPoolExecutor} constructors.
185      *
186      * @return the newly created thread pool
187      */
newCachedThreadPool()188     public static ExecutorService newCachedThreadPool() {
189         return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
190                                       60L, TimeUnit.SECONDS,
191                                       new SynchronousQueue<Runnable>());
192     }
193 
194     /**
195      * Creates a thread pool that creates new threads as needed, but
196      * will reuse previously constructed threads when they are
197      * available, and uses the provided
198      * ThreadFactory to create new threads when needed.
199      * @param threadFactory the factory to use when creating new threads
200      * @return the newly created thread pool
201      * @throws NullPointerException if threadFactory is null
202      */
newCachedThreadPool(ThreadFactory threadFactory)203     public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
204         return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
205                                       60L, TimeUnit.SECONDS,
206                                       new SynchronousQueue<Runnable>(),
207                                       threadFactory);
208     }
209 
210     /**
211      * Creates a single-threaded executor that can schedule commands
212      * to run after a given delay, or to execute periodically.
213      * (Note however that if this single
214      * thread terminates due to a failure during execution prior to
215      * shutdown, a new one will take its place if needed to execute
216      * subsequent tasks.)  Tasks are guaranteed to execute
217      * sequentially, and no more than one task will be active at any
218      * given time. Unlike the otherwise equivalent
219      * {@code newScheduledThreadPool(1)} the returned executor is
220      * guaranteed not to be reconfigurable to use additional threads.
221      * @return the newly created scheduled executor
222      */
newSingleThreadScheduledExecutor()223     public static ScheduledExecutorService newSingleThreadScheduledExecutor() {
224         return new DelegatedScheduledExecutorService
225             (new ScheduledThreadPoolExecutor(1));
226     }
227 
228     /**
229      * Creates a single-threaded executor that can schedule commands
230      * to run after a given delay, or to execute periodically.  (Note
231      * however that if this single thread terminates due to a failure
232      * during execution prior to shutdown, a new one will take its
233      * place if needed to execute subsequent tasks.)  Tasks are
234      * guaranteed to execute sequentially, and no more than one task
235      * will be active at any given time. Unlike the otherwise
236      * equivalent {@code newScheduledThreadPool(1, threadFactory)}
237      * the returned executor is guaranteed not to be reconfigurable to
238      * use additional threads.
239      * @param threadFactory the factory to use when creating new
240      * threads
241      * @return a newly created scheduled executor
242      * @throws NullPointerException if threadFactory is null
243      */
newSingleThreadScheduledExecutor(ThreadFactory threadFactory)244     public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory) {
245         return new DelegatedScheduledExecutorService
246             (new ScheduledThreadPoolExecutor(1, threadFactory));
247     }
248 
249     /**
250      * Creates a thread pool that can schedule commands to run after a
251      * given delay, or to execute periodically.
252      * @param corePoolSize the number of threads to keep in the pool,
253      * even if they are idle
254      * @return a newly created scheduled thread pool
255      * @throws IllegalArgumentException if {@code corePoolSize < 0}
256      */
newScheduledThreadPool(int corePoolSize)257     public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
258         return new ScheduledThreadPoolExecutor(corePoolSize);
259     }
260 
261     /**
262      * Creates a thread pool that can schedule commands to run after a
263      * given delay, or to execute periodically.
264      * @param corePoolSize the number of threads to keep in the pool,
265      * even if they are idle
266      * @param threadFactory the factory to use when the executor
267      * creates a new thread
268      * @return a newly created scheduled thread pool
269      * @throws IllegalArgumentException if {@code corePoolSize < 0}
270      * @throws NullPointerException if threadFactory is null
271      */
newScheduledThreadPool( int corePoolSize, ThreadFactory threadFactory)272     public static ScheduledExecutorService newScheduledThreadPool(
273             int corePoolSize, ThreadFactory threadFactory) {
274         return new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
275     }
276 
277     /**
278      * Returns an object that delegates all defined {@link
279      * ExecutorService} methods to the given executor, but not any
280      * other methods that might otherwise be accessible using
281      * casts. This provides a way to safely "freeze" configuration and
282      * disallow tuning of a given concrete implementation.
283      * @param executor the underlying implementation
284      * @return an {@code ExecutorService} instance
285      * @throws NullPointerException if executor null
286      */
unconfigurableExecutorService(ExecutorService executor)287     public static ExecutorService unconfigurableExecutorService(ExecutorService executor) {
288         if (executor == null)
289             throw new NullPointerException();
290         return new DelegatedExecutorService(executor);
291     }
292 
293     /**
294      * Returns an object that delegates all defined {@link
295      * ScheduledExecutorService} methods to the given executor, but
296      * not any other methods that might otherwise be accessible using
297      * casts. This provides a way to safely "freeze" configuration and
298      * disallow tuning of a given concrete implementation.
299      * @param executor the underlying implementation
300      * @return a {@code ScheduledExecutorService} instance
301      * @throws NullPointerException if executor null
302      */
unconfigurableScheduledExecutorService(ScheduledExecutorService executor)303     public static ScheduledExecutorService unconfigurableScheduledExecutorService(ScheduledExecutorService executor) {
304         if (executor == null)
305             throw new NullPointerException();
306         return new DelegatedScheduledExecutorService(executor);
307     }
308 
309     /**
310      * Returns a default thread factory used to create new threads.
311      * This factory creates all new threads used by an Executor in the
312      * same {@link ThreadGroup}. Each new
313      * thread is created as a non-daemon thread with priority set to
314      * the smaller of {@code Thread.NORM_PRIORITY} and the maximum
315      * priority permitted in the thread group.  New threads have names
316      * accessible via {@link Thread#getName} of
317      * <em>pool-N-thread-M</em>, where <em>N</em> is the sequence
318      * number of this factory, and <em>M</em> is the sequence number
319      * of the thread created by this factory.
320      * @return a thread factory
321      */
defaultThreadFactory()322     public static ThreadFactory defaultThreadFactory() {
323         return new DefaultThreadFactory();
324     }
325 
326     /**
327      * Legacy security code; do not use.
328      */
privilegedThreadFactory()329     public static ThreadFactory privilegedThreadFactory() {
330         return new PrivilegedThreadFactory();
331     }
332 
333     /**
334      * Returns a {@link Callable} object that, when
335      * called, runs the given task and returns the given result.  This
336      * can be useful when applying methods requiring a
337      * {@code Callable} to an otherwise resultless action.
338      * @param task the task to run
339      * @param result the result to return
340      * @return a callable object
341      * @throws NullPointerException if task null
342      */
callable(Runnable task, T result)343     public static <T> Callable<T> callable(Runnable task, T result) {
344         if (task == null)
345             throw new NullPointerException();
346         return new RunnableAdapter<T>(task, result);
347     }
348 
349     /**
350      * Returns a {@link Callable} object that, when
351      * called, runs the given task and returns {@code null}.
352      * @param task the task to run
353      * @return a callable object
354      * @throws NullPointerException if task null
355      */
callable(Runnable task)356     public static Callable<Object> callable(Runnable task) {
357         if (task == null)
358             throw new NullPointerException();
359         return new RunnableAdapter<Object>(task, null);
360     }
361 
362     /**
363      * Returns a {@link Callable} object that, when
364      * called, runs the given privileged action and returns its result.
365      * @param action the privileged action to run
366      * @return a callable object
367      * @throws NullPointerException if action null
368      */
callable(final PrivilegedAction<?> action)369     public static Callable<Object> callable(final PrivilegedAction<?> action) {
370         if (action == null)
371             throw new NullPointerException();
372         return new Callable<Object>() {
373             public Object call() { return action.run(); }};
374     }
375 
376     /**
377      * Returns a {@link Callable} object that, when
378      * called, runs the given privileged exception action and returns
379      * its result.
380      * @param action the privileged exception action to run
381      * @return a callable object
382      * @throws NullPointerException if action null
383      */
384     public static Callable<Object> callable(final PrivilegedExceptionAction<?> action) {
385         if (action == null)
386             throw new NullPointerException();
387         return new Callable<Object>() {
388             public Object call() throws Exception { return action.run(); }};
389     }
390 
391     /**
392      * Legacy security code; do not use.
393      */
394     public static <T> Callable<T> privilegedCallable(Callable<T> callable) {
395         if (callable == null)
396             throw new NullPointerException();
397         return new PrivilegedCallable<T>(callable);
398     }
399 
400     /**
401      * Legacy security code; do not use.
402      */
403     public static <T> Callable<T> privilegedCallableUsingCurrentClassLoader(Callable<T> callable) {
404         if (callable == null)
405             throw new NullPointerException();
406         return new PrivilegedCallableUsingCurrentClassLoader<T>(callable);
407     }
408 
409     // Non-public classes supporting the public methods
410 
411     /**
412      * A callable that runs given task and returns given result
413      */
414     static final class RunnableAdapter<T> implements Callable<T> {
415         final Runnable task;
416         final T result;
417         RunnableAdapter(Runnable task, T result) {
418             this.task = task;
419             this.result = result;
420         }
421         public T call() {
422             task.run();
423             return result;
424         }
425     }
426 
427     /**
428      * A callable that runs under established access control settings
429      */
430     static final class PrivilegedCallable<T> implements Callable<T> {
431         private final Callable<T> task;
432         private final AccessControlContext acc;
433 
434         PrivilegedCallable(Callable<T> task) {
435             this.task = task;
436             this.acc = AccessController.getContext();
437         }
438 
439         public T call() throws Exception {
440             try {
441                 return AccessController.doPrivileged(
442                     new PrivilegedExceptionAction<T>() {
443                         public T run() throws Exception {
444                             return task.call();
445                         }
446                     }, acc);
447             } catch (PrivilegedActionException e) {
448                 throw e.getException();
449             }
450         }
451     }
452 
453     /**
454      * A callable that runs under established access control settings and
455      * current ClassLoader
456      */
457     static final class PrivilegedCallableUsingCurrentClassLoader<T> implements Callable<T> {
458         private final Callable<T> task;
459         private final AccessControlContext acc;
460         private final ClassLoader ccl;
461 
462         PrivilegedCallableUsingCurrentClassLoader(Callable<T> task) {
463             // BEGIN android-removed
464             // SecurityManager sm = System.getSecurityManager();
465             // if (sm != null) {
466             //     // Calls to getContextClassLoader from this class
467             //     // never trigger a security check, but we check
468             //     // whether our callers have this permission anyways.
469             //     sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
470             //
471             //     // Whether setContextClassLoader turns out to be necessary
472             //     // or not, we fail fast if permission is not available.
473             //     sm.checkPermission(new RuntimePermission("setContextClassLoader"));
474             // }
475             // END android-removed
476             this.task = task;
477             this.acc = AccessController.getContext();
478             this.ccl = Thread.currentThread().getContextClassLoader();
479         }
480 
481         public T call() throws Exception {
482             try {
483                 return AccessController.doPrivileged(
484                     new PrivilegedExceptionAction<T>() {
485                         public T run() throws Exception {
486                             Thread t = Thread.currentThread();
487                             ClassLoader cl = t.getContextClassLoader();
488                             if (ccl == cl) {
489                                 return task.call();
490                             } else {
491                                 t.setContextClassLoader(ccl);
492                                 try {
493                                     return task.call();
494                                 } finally {
495                                     t.setContextClassLoader(cl);
496                                 }
497                             }
498                         }
499                     }, acc);
500             } catch (PrivilegedActionException e) {
501                 throw e.getException();
502             }
503         }
504     }
505 
506     /**
507      * The default thread factory
508      */
509     static class DefaultThreadFactory implements ThreadFactory {
510         private static final AtomicInteger poolNumber = new AtomicInteger(1);
511         private final ThreadGroup group;
512         private final AtomicInteger threadNumber = new AtomicInteger(1);
513         private final String namePrefix;
514 
515         DefaultThreadFactory() {
516             SecurityManager s = System.getSecurityManager();
517             group = (s != null) ? s.getThreadGroup() :
518                                   Thread.currentThread().getThreadGroup();
519             namePrefix = "pool-" +
520                           poolNumber.getAndIncrement() +
521                          "-thread-";
522         }
523 
524         public Thread newThread(Runnable r) {
525             Thread t = new Thread(group, r,
526                                   namePrefix + threadNumber.getAndIncrement(),
527                                   0);
528             if (t.isDaemon())
529                 t.setDaemon(false);
530             if (t.getPriority() != Thread.NORM_PRIORITY)
531                 t.setPriority(Thread.NORM_PRIORITY);
532             return t;
533         }
534     }
535 
536     /**
537      * Thread factory capturing access control context and class loader
538      */
539     static class PrivilegedThreadFactory extends DefaultThreadFactory {
540         private final AccessControlContext acc;
541         private final ClassLoader ccl;
542 
543         PrivilegedThreadFactory() {
544             super();
545             // BEGIN android-removed
546             // SecurityManager sm = System.getSecurityManager();
547             // if (sm != null) {
548             //     // Calls to getContextClassLoader from this class
549             //     // never trigger a security check, but we check
550             //     // whether our callers have this permission anyways.
551             //     sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
552             //
553             //     // Fail fast
554             //     sm.checkPermission(new RuntimePermission("setContextClassLoader"));
555             // }
556             // END android-removed
557             this.acc = AccessController.getContext();
558             this.ccl = Thread.currentThread().getContextClassLoader();
559         }
560 
561         public Thread newThread(final Runnable r) {
562             return super.newThread(new Runnable() {
563                 public void run() {
564                     AccessController.doPrivileged(new PrivilegedAction<Void>() {
565                         public Void run() {
566                             Thread.currentThread().setContextClassLoader(ccl);
567                             r.run();
568                             return null;
569                         }
570                     }, acc);
571                 }
572             });
573         }
574     }
575 
576     /**
577      * A wrapper class that exposes only the ExecutorService methods
578      * of an ExecutorService implementation.
579      */
580     static class DelegatedExecutorService extends AbstractExecutorService {
581         private final ExecutorService e;
582         DelegatedExecutorService(ExecutorService executor) { e = executor; }
583         public void execute(Runnable command) { e.execute(command); }
584         public void shutdown() { e.shutdown(); }
585         public List<Runnable> shutdownNow() { return e.shutdownNow(); }
586         public boolean isShutdown() { return e.isShutdown(); }
587         public boolean isTerminated() { return e.isTerminated(); }
588         public boolean awaitTermination(long timeout, TimeUnit unit)
589             throws InterruptedException {
590             return e.awaitTermination(timeout, unit);
591         }
592         public Future<?> submit(Runnable task) {
593             return e.submit(task);
594         }
595         public <T> Future<T> submit(Callable<T> task) {
596             return e.submit(task);
597         }
598         public <T> Future<T> submit(Runnable task, T result) {
599             return e.submit(task, result);
600         }
601         public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
602             throws InterruptedException {
603             return e.invokeAll(tasks);
604         }
605         public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
606                                              long timeout, TimeUnit unit)
607             throws InterruptedException {
608             return e.invokeAll(tasks, timeout, unit);
609         }
610         public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
611             throws InterruptedException, ExecutionException {
612             return e.invokeAny(tasks);
613         }
614         public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
615                                long timeout, TimeUnit unit)
616             throws InterruptedException, ExecutionException, TimeoutException {
617             return e.invokeAny(tasks, timeout, unit);
618         }
619     }
620 
621     static class FinalizableDelegatedExecutorService
622         extends DelegatedExecutorService {
623         FinalizableDelegatedExecutorService(ExecutorService executor) {
624             super(executor);
625         }
626         protected void finalize() {
627             super.shutdown();
628         }
629     }
630 
631     /**
632      * A wrapper class that exposes only the ScheduledExecutorService
633      * methods of a ScheduledExecutorService implementation.
634      */
635     static class DelegatedScheduledExecutorService
636             extends DelegatedExecutorService
637             implements ScheduledExecutorService {
638         private final ScheduledExecutorService e;
639         DelegatedScheduledExecutorService(ScheduledExecutorService executor) {
640             super(executor);
641             e = executor;
642         }
643         public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
644             return e.schedule(command, delay, unit);
645         }
646         public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
647             return e.schedule(callable, delay, unit);
648         }
649         public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
650             return e.scheduleAtFixedRate(command, initialDelay, period, unit);
651         }
652         public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
653             return e.scheduleWithFixedDelay(command, initialDelay, delay, unit);
654         }
655     }
656 
657     /** Cannot instantiate. */
658     private Executors() {}
659 }
660