0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This file is available under and governed by the GNU General Public 0N/A * License version 2 only, as published by the Free Software Foundation. 0N/A * However, the following notice accompanied the original version of this 0N/A * Written by Doug Lea with assistance from members of JCP JSR-166 0N/A * Expert Group and released to the public domain, as explained at 0N/A * Provides default implementations of {@link ExecutorService} 0N/A * execution methods. This class implements the <tt>submit</tt>, 0N/A * <tt>invokeAny</tt> and <tt>invokeAll</tt> methods using a 0N/A * {@link RunnableFuture} returned by <tt>newTaskFor</tt>, which defaults 0N/A * to the {@link FutureTask} class provided in this package. For example, 0N/A * the implementation of <tt>submit(Runnable)</tt> creates an 0N/A * associated <tt>RunnableFuture</tt> that is executed and 0N/A * returned. Subclasses may override the <tt>newTaskFor</tt> methods 0N/A * to return <tt>RunnableFuture</tt> implementations other than 0N/A * <tt>FutureTask</tt>. 0N/A * <p> <b>Extension example</b>. Here is a sketch of a class 0N/A * that customizes {@link ThreadPoolExecutor} to use 0N/A * a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>: 0N/A * public class CustomThreadPoolExecutor extends ThreadPoolExecutor { 3203N/A * static class CustomTask<V> implements RunnableFuture<V> {...} 3203N/A * protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) { 3203N/A * return new CustomTask<V>(c); 3203N/A * protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) { 3203N/A * return new CustomTask<V>(r, v); 0N/A * // ... add constructors, etc. 0N/A * Returns a <tt>RunnableFuture</tt> for the given runnable and default 0N/A * @param runnable the runnable task being wrapped 0N/A * @param value the default value for the returned future 0N/A * @return a <tt>RunnableFuture</tt> which when run will run the 0N/A * underlying runnable and which, as a <tt>Future</tt>, will yield 0N/A * the given value as its result and provide for cancellation of 0N/A * the underlying task. 0N/A * Returns a <tt>RunnableFuture</tt> for the given callable task. 0N/A * @param callable the callable task being wrapped 0N/A * @return a <tt>RunnableFuture</tt> which when run will call the 0N/A * underlying callable and which, as a <tt>Future</tt>, will yield 0N/A * the callable's result as its result and provide for 0N/A * cancellation of the underlying task. 0N/A * @throws RejectedExecutionException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws RejectedExecutionException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws RejectedExecutionException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * the main mechanics of invokeAny. 0N/A // For efficiency, especially in executors with limited 0N/A // parallelism, check to see if previously submitted tasks are 0N/A // done before submitting more of them. This interleaving 0N/A // plus the exception mechanics account for messiness of main 0N/A // Record exceptions so that if we fail to obtain any 0N/A // result, we can throw the last exception we got. 0N/A // Start one task for sure; the rest incrementally 0N/A // Interleave time checks and calls to execute in case