Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/Executors.java
          +++ new/src/share/classes/java/util/concurrent/Executors.java
↓ open down ↓ 75 lines elided ↑ open up ↑
  76   76       * <tt>nThreads</tt> threads will be active processing tasks.
  77   77       * If additional tasks are submitted when all threads are active,
  78   78       * they will wait in the queue until a thread is available.
  79   79       * If any thread terminates due to a failure during execution
  80   80       * prior to shutdown, a new one will take its place if needed to
  81   81       * execute subsequent tasks.  The threads in the pool will exist
  82   82       * until it is explicitly {@link ExecutorService#shutdown shutdown}.
  83   83       *
  84   84       * @param nThreads the number of threads in the pool
  85   85       * @return the newly created thread pool
  86      -     * @throws IllegalArgumentException if <tt>nThreads &lt;= 0</tt>
       86 +     * @throws IllegalArgumentException if {@code nThreads <= 0}
  87   87       */
  88   88      public static ExecutorService newFixedThreadPool(int nThreads) {
  89   89          return new ThreadPoolExecutor(nThreads, nThreads,
  90   90                                        0L, TimeUnit.MILLISECONDS,
  91   91                                        new LinkedBlockingQueue<Runnable>());
  92   92      }
  93   93  
  94   94      /**
  95   95       * Creates a thread pool that reuses a fixed number of threads
  96   96       * operating off a shared unbounded queue, using the provided
↓ open down ↓ 4 lines elided ↑ open up ↑
 101  101       * available.  If any thread terminates due to a failure during
 102  102       * execution prior to shutdown, a new one will take its place if
 103  103       * needed to execute subsequent tasks.  The threads in the pool will
 104  104       * exist until it is explicitly {@link ExecutorService#shutdown
 105  105       * shutdown}.
 106  106       *
 107  107       * @param nThreads the number of threads in the pool
 108  108       * @param threadFactory the factory to use when creating new threads
 109  109       * @return the newly created thread pool
 110  110       * @throws NullPointerException if threadFactory is null
 111      -     * @throws IllegalArgumentException if <tt>nThreads &lt;= 0</tt>
      111 +     * @throws IllegalArgumentException if {@code nThreads <= 0}
 112  112       */
 113  113      public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) {
 114  114          return new ThreadPoolExecutor(nThreads, nThreads,
 115  115                                        0L, TimeUnit.MILLISECONDS,
 116  116                                        new LinkedBlockingQueue<Runnable>(),
 117  117                                        threadFactory);
 118  118      }
 119  119  
 120  120      /**
 121  121       * Creates an Executor that uses a single worker thread operating
↓ open down ↓ 113 lines elided ↑ open up ↑
 235  235          return new DelegatedScheduledExecutorService
 236  236              (new ScheduledThreadPoolExecutor(1, threadFactory));
 237  237      }
 238  238  
 239  239      /**
 240  240       * Creates a thread pool that can schedule commands to run after a
 241  241       * given delay, or to execute periodically.
 242  242       * @param corePoolSize the number of threads to keep in the pool,
 243  243       * even if they are idle.
 244  244       * @return a newly created scheduled thread pool
 245      -     * @throws IllegalArgumentException if <tt>corePoolSize &lt; 0</tt>
      245 +     * @throws IllegalArgumentException if {@code corePoolSize < 0}
 246  246       */
 247  247      public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
 248  248          return new ScheduledThreadPoolExecutor(corePoolSize);
 249  249      }
 250  250  
 251  251      /**
 252  252       * Creates a thread pool that can schedule commands to run after a
 253  253       * given delay, or to execute periodically.
 254  254       * @param corePoolSize the number of threads to keep in the pool,
 255  255       * even if they are idle.
 256  256       * @param threadFactory the factory to use when the executor
 257  257       * creates a new thread.
 258  258       * @return a newly created scheduled thread pool
 259      -     * @throws IllegalArgumentException if <tt>corePoolSize &lt; 0</tt>
      259 +     * @throws IllegalArgumentException if {@code corePoolSize < 0}
 260  260       * @throws NullPointerException if threadFactory is null
 261  261       */
 262  262      public static ScheduledExecutorService newScheduledThreadPool(
 263  263              int corePoolSize, ThreadFactory threadFactory) {
 264  264          return new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
 265  265      }
 266  266  
 267  267  
 268  268      /**
 269  269       * Returns an object that delegates all defined {@link
↓ open down ↓ 285 lines elided ↑ open up ↑
 555  555       * The default thread factory
 556  556       */
 557  557      static class DefaultThreadFactory implements ThreadFactory {
 558  558          private static final AtomicInteger poolNumber = new AtomicInteger(1);
 559  559          private final ThreadGroup group;
 560  560          private final AtomicInteger threadNumber = new AtomicInteger(1);
 561  561          private final String namePrefix;
 562  562  
 563  563          DefaultThreadFactory() {
 564  564              SecurityManager s = System.getSecurityManager();
 565      -            group = (s != null)? s.getThreadGroup() :
 566      -                                 Thread.currentThread().getThreadGroup();
      565 +            group = (s != null) ? s.getThreadGroup() :
      566 +                                  Thread.currentThread().getThreadGroup();
 567  567              namePrefix = "pool-" +
 568  568                            poolNumber.getAndIncrement() +
 569  569                           "-thread-";
 570  570          }
 571  571  
 572  572          public Thread newThread(Runnable r) {
 573  573              Thread t = new Thread(group, r,
 574  574                                    namePrefix + threadNumber.getAndIncrement(),
 575  575                                    0);
 576  576              if (t.isDaemon())
↓ open down ↓ 85 lines elided ↑ open up ↑
 662  662              throws InterruptedException, ExecutionException, TimeoutException {
 663  663              return e.invokeAny(tasks, timeout, unit);
 664  664          }
 665  665      }
 666  666  
 667  667      static class FinalizableDelegatedExecutorService
 668  668          extends DelegatedExecutorService {
 669  669          FinalizableDelegatedExecutorService(ExecutorService executor) {
 670  670              super(executor);
 671  671          }
 672      -        protected void finalize()  {
      672 +        protected void finalize() {
 673  673              super.shutdown();
 674  674          }
 675  675      }
 676  676  
 677  677      /**
 678  678       * A wrapper class that exposes only the ScheduledExecutorService
 679  679       * methods of a ScheduledExecutorService implementation.
 680  680       */
 681  681      static class DelegatedScheduledExecutorService
 682  682              extends DelegatedExecutorService
↓ open down ↓ 24 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX