src/share/classes/java/util/concurrent/AbstractExecutorService.java

Print this page

        

*** 49,72 **** * <tt>FutureTask</tt>. * * <p> <b>Extension example</b>. Here is a sketch of a class * that customizes {@link ThreadPoolExecutor} to use * a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>: ! * <pre> * public class CustomThreadPoolExecutor extends ThreadPoolExecutor { * ! * static class CustomTask&lt;V&gt; implements RunnableFuture&lt;V&gt; {...} * ! * protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Callable&lt;V&gt; c) { ! * return new CustomTask&lt;V&gt;(c); * } ! * protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Runnable r, V v) { ! * return new CustomTask&lt;V&gt;(r, v); * } * // ... add constructors, etc. ! * } ! * </pre> * @since 1.5 * @author Doug Lea */ public abstract class AbstractExecutorService implements ExecutorService { --- 49,72 ---- * <tt>FutureTask</tt>. * * <p> <b>Extension example</b>. Here is a sketch of a class * that customizes {@link ThreadPoolExecutor} to use * a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>: ! * <pre> {@code * public class CustomThreadPoolExecutor extends ThreadPoolExecutor { * ! * static class CustomTask<V> implements RunnableFuture<V> {...} * ! * protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) { ! * return new CustomTask<V>(c); * } ! * protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) { ! * return new CustomTask<V>(r, v); * } * // ... add constructors, etc. ! * }}</pre> ! * * @since 1.5 * @author Doug Lea */ public abstract class AbstractExecutorService implements ExecutorService {
*** 104,114 **** * @throws RejectedExecutionException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ public Future<?> submit(Runnable task) { if (task == null) throw new NullPointerException(); ! RunnableFuture<Object> ftask = newTaskFor(task, null); execute(ftask); return ftask; } /** --- 104,114 ---- * @throws RejectedExecutionException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ public Future<?> submit(Runnable task) { if (task == null) throw new NullPointerException(); ! RunnableFuture<Void> ftask = newTaskFor(task, null); execute(ftask); return ftask; } /**
*** 156,166 **** try { // Record exceptions so that if we fail to obtain any // result, we can throw the last exception we got. ExecutionException ee = null; ! long lastTime = (timed)? System.nanoTime() : 0; Iterator<? extends Callable<T>> it = tasks.iterator(); // Start one task for sure; the rest incrementally futures.add(ecs.submit(it.next())); --ntasks; --- 156,166 ---- try { // Record exceptions so that if we fail to obtain any // result, we can throw the last exception we got. ExecutionException ee = null; ! long lastTime = timed ? System.nanoTime() : 0; Iterator<? extends Callable<T>> it = tasks.iterator(); // Start one task for sure; the rest incrementally futures.add(ecs.submit(it.next())); --ntasks;
*** 189,200 **** } if (f != null) { --active; try { return f.get(); - } catch (InterruptedException ie) { - throw ie; } catch (ExecutionException eex) { ee = eex; } catch (RuntimeException rex) { ee = new ExecutionException(rex); } --- 189,198 ----