[concurrency-interest] Proposal for a CallerRunsExecutor in j.u.c.Executors

Martin Buchholz martinrb at google.com
Mon Jun 23 18:51:38 EDT 2014


--- src/main/java/util/concurrent/Executors.java 18 Jul 2013 17:13:42 -0000
1.88
+++ src/main/java/util/concurrent/Executors.java 23 Jun 2014 22:49:59 -0000
@@ -167,6 +167,21 @@
                                     threadFactory));
     }

+    private static class CallerRunsExecutor implements Executor {
+        static final CallerRunsExecutor INSTANCE = new
CallerRunsExecutor();
+        public void execute(Runnable r) { r.run(); }
+    }
+
+    /**
+     * Returns an Executor that runs tasks in the current thread.
+     * Tasks run entirely during calls to {@link Executor#execute}.
+     *
+     * @return a caller-runs Executor
+     */
+    public static Executor callerRunsExecutor() {
+        return CallerRunsExecutor.INSTANCE;
+    }
+
     /**
      * Creates a thread pool that creates new threads as needed, but
      * will reuse previously constructed threads when they are
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140623/c645a616/attachment.html>


More information about the Concurrency-interest mailing list