harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r800399 - in /harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent: AbstractExecutorService.java ExecutorCompletionService.java FutureTask.java RunnableFuture.java RunnableScheduledFuture.java
Date Mon, 03 Aug 2009 14:22:25 GMT
Author: hindessm
Date: Mon Aug  3 14:22:25 2009
New Revision: 800399

URL: http://svn.apache.org/viewvc?rev=800399&view=rev
Log:
Put back RunableFuture class.

Added:
    harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableFuture.java
  (with props)
    harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableScheduledFuture.java
  (with props)
Modified:
    harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/AbstractExecutorService.java
    harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/ExecutorCompletionService.java
    harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/FutureTask.java

Modified: harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/AbstractExecutorService.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/AbstractExecutorService.java?rev=800399&r1=800398&r2=800399&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/AbstractExecutorService.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/AbstractExecutorService.java
Mon Aug  3 14:22:25 2009
@@ -10,26 +10,74 @@
 /**
  * Provides default implementations of {@link ExecutorService}
  * execution methods. This class implements the <tt>submit</tt>,
- * <tt>invokeAny</tt> and <tt>invokeAll</tt> methods using the default
- * {@link FutureTask} class provided in this package.  For example,
+ * <tt>invokeAny</tt> and <tt>invokeAll</tt> methods using a
+ * {@link RunnableFuture} returned by <tt>newTaskFor</tt>, which defaults
+ * to the {@link FutureTask} class provided in this package.  For example,
  * the implementation of <tt>submit(Runnable)</tt> creates an
- * associated <tt>FutureTask</tt> that is executed and
- * returned. Subclasses overriding these methods to use different
- * {@link Future} implementations should do so consistently for each
- * of these methods.
+ * associated <tt>RunnableFuture</tt> that is executed and
+ * returned. Subclasses may override the <tt>newTaskFor</tt> methods
+ * to return <tt>RunnableFuture</tt> implementations other than
+ * <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 {
 
     /**
+     * Returns a <tt>RunnableFuture</tt> for the given runnable and default
+     * value.
+     *
+     * @param runnable the runnable task being wrapped
+     * @param value the default value for the returned future
+     * @return a <tt>RunnableFuture</tt> which when run will run the
+     * underlying runnable and which, as a <tt>Future</tt>, will yield
+     * the given value as its result and provide for cancellation of
+     * the underlying task.
+     * @since 1.6
+     */
+    protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
+        return new FutureTask<T>(runnable, value);
+    }
+
+    /**
+     * Returns a <tt>RunnableFuture</tt> for the given callable task.
+     *
+     * @param callable the callable task being wrapped
+     * @return a <tt>RunnableFuture</tt> which when run will call the
+     * underlying callable and which, as a <tt>Future</tt>, will yield
+     * the callable's result as its result and provide for
+     * cancellation of the underlying task.
+     * @since 1.6
+     */
+    protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
+        return new FutureTask<T>(callable);
+    }
+
+    /**
      * @throws RejectedExecutionException {@inheritDoc}
      * @throws NullPointerException       {@inheritDoc}
      */
     public Future<?> submit(Runnable task) {
         if (task == null) throw new NullPointerException();
-        FutureTask<Object> ftask = new FutureTask<Object>(task, null);
+        RunnableFuture<Object> ftask = newTaskFor(task, null);
         execute(ftask);
         return ftask;
     }
@@ -40,7 +88,7 @@
      */
     public <T> Future<T> submit(Runnable task, T result) {
         if (task == null) throw new NullPointerException();
-        FutureTask<T> ftask = new FutureTask<T>(task, result);
+        RunnableFuture<T> ftask = newTaskFor(task, result);
         execute(ftask);
         return ftask;
     }
@@ -51,7 +99,7 @@
      */
     public <T> Future<T> submit(Callable<T> task) {
         if (task == null) throw new NullPointerException();
-        FutureTask<T> ftask = new FutureTask<T>(task);
+        RunnableFuture<T> ftask = newTaskFor(task);
         execute(ftask);
         return ftask;
     }
@@ -158,7 +206,7 @@
         boolean done = false;
         try {
             for (Callable<T> t : tasks) {
-                FutureTask<T> f = new FutureTask<T>(t);
+                RunnableFuture<T> f = newTaskFor(t);
                 futures.add(f);
                 execute(f);
             }
@@ -190,7 +238,7 @@
         boolean done = false;
         try {
             for (Callable<T> t : tasks)
-                futures.add(new FutureTask<T>(t));
+                futures.add(newTaskFor(t));
 
             long lastTime = System.nanoTime();
 

Modified: harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/ExecutorCompletionService.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/ExecutorCompletionService.java?rev=800399&r1=800398&r2=800399&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/ExecutorCompletionService.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/ExecutorCompletionService.java
Mon Aug  3 14:22:25 2009
@@ -84,7 +84,7 @@
      * FutureTask extension to enqueue upon completion
      */
     private class QueueingFuture extends FutureTask<Void> {
-        QueueingFuture(FutureTask<V> task) {
+        QueueingFuture(RunnableFuture<V> task) {
             super(task, null);
             this.task = task;
         }
@@ -92,12 +92,18 @@
         private final Future<V> task;
     }
 
-    private FutureTask<V> newTaskFor(Callable<V> task) {
+    private RunnableFuture<V> newTaskFor(Callable<V> task) {
+        if (aes == null)
         return new FutureTask<V>(task);
+        else
+            return aes.newTaskFor(task);
     }
 
-    private FutureTask<V> newTaskFor(Runnable task, V result) {
+    private RunnableFuture<V> newTaskFor(Runnable task, V result) {
+        if (aes == null)
         return new FutureTask<V>(task, result);
+        else
+            return aes.newTaskFor(task, result);
     }
 
     /**
@@ -142,14 +148,14 @@
 
     public Future<V> submit(Callable<V> task) {
         if (task == null) throw new NullPointerException();
-        FutureTask<V> f = newTaskFor(task);
+        RunnableFuture<V> f = newTaskFor(task);
         executor.execute(new QueueingFuture(f));
         return f;
     }
 
     public Future<V> submit(Runnable task, V result) {
         if (task == null) throw new NullPointerException();
-        FutureTask<V> f = newTaskFor(task, result);
+        RunnableFuture<V> f = newTaskFor(task, result);
         executor.execute(new QueueingFuture(f));
         return f;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/FutureTask.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/FutureTask.java?rev=800399&r1=800398&r2=800399&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/FutureTask.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/FutureTask.java
Mon Aug  3 14:22:25 2009
@@ -30,7 +30,7 @@
  * @author Doug Lea
  * @param <V> The result type returned by this FutureTask's <tt>get</tt>
method
  */
-public class FutureTask<V> implements Future<V>, Runnable {
+public class FutureTask<V> implements RunnableFuture<V> {
     /** Synchronization control for FutureTask */
     private final Sync sync;
 

Added: harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableFuture.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableFuture.java?rev=800399&view=auto
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableFuture.java
(added)
+++ harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableFuture.java
Mon Aug  3 14:22:25 2009
@@ -0,0 +1,25 @@
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ */
+
+package java.util.concurrent;
+
+/**
+ * A {@link Future} that is {@link Runnable}. Successful execution of
+ * the <tt>run</tt> method causes completion of the <tt>Future</tt>
+ * and allows access to its results.
+ * @see FutureTask
+ * @see Executor
+ * @since 1.6
+ * @author Doug Lea
+ * @param <V> The result type returned by this Future's <tt>get</tt> method
+ */
+public interface RunnableFuture<V> extends Runnable, Future<V> {
+    /**
+     * Sets this Future to the result of its computation
+     * unless it has been cancelled.
+     */
+    void run();
+}

Propchange: harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableFuture.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableScheduledFuture.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableScheduledFuture.java?rev=800399&view=auto
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableScheduledFuture.java
(added)
+++ harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableScheduledFuture.java
Mon Aug  3 14:22:25 2009
@@ -0,0 +1,29 @@
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ */
+
+package java.util.concurrent;
+
+/**
+ * A {@link ScheduledFuture} that is {@link Runnable}. Successful
+ * execution of the <tt>run</tt> method causes completion of the
+ * <tt>Future</tt> and allows access to its results.
+ * @see FutureTask
+ * @see Executor
+ * @since 1.6
+ * @author Doug Lea
+ * @param <V> The result type returned by this Future's <tt>get</tt> method
+ */
+public interface RunnableScheduledFuture<V> extends RunnableFuture<V>, ScheduledFuture<V>
{
+
+    /**
+     * Returns true if this is a periodic task. A periodic task may
+     * re-run according to some schedule. A non-periodic task can be
+     * run only once.
+     *
+     * @return true if this task is periodic
+     */
+    boolean isPeriodic();
+}

Propchange: harmony/enhanced/classlib/branches/java6/modules/concurrent/src/main/java/java/util/concurrent/RunnableScheduledFuture.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message