src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SequentialScheduler.java
branchhttp-client-branch
changeset 55768 8674257c75ce
parent 55763 634d8e14c172
child 55973 4d9b002587db
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SequentialScheduler.java	Mon Nov 06 13:06:34 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SequentialScheduler.java	Mon Nov 06 18:17:09 2017 +0000
@@ -343,4 +343,22 @@
     public void stop() {
         state.set(STOP);
     }
+
+    /**
+     * Returns a new {@code SequentialScheduler} that executes the provided
+     * {@code mainLoop} from within a {@link SynchronizedRestartableTask}.
+     *
+     * @apiNote
+     * This is equivalent to calling
+     * {@code new SequentialScheduler(new SynchronizedRestartableTask(mainloop));}
+     * The main loop must not do any blocking operation.
+     *
+     * @param mainloop The main loop of the new sequential scheduler.
+     * @return a new {@code SequentialScheduler} that executes the provided
+     * {@code mainLoop} from within a {@link SynchronizedRestartableTask}.
+     */
+    public static SequentialScheduler synchronizedScheduler(Runnable mainloop) {
+        return new SequentialScheduler(new SynchronizedRestartableTask(mainloop));
+    }
+
 }