@@ -54,9 +54,6 @@ private void run() {
5454 for (; ; ) {
5555 final ExecuteTask execute ;
5656 synchronized (tasks ) {
57- if (closed ) {
58- return ;
59- }
6057 Task task = tasks .poll ();
6158 if (task == null ) {
6259 currentExecutor = null ;
@@ -125,9 +122,6 @@ private ContinuationTask continuationTask() {
125122 */
126123 public void execute (Runnable task , Executor executor ) throws RejectedExecutionException {
127124 synchronized (tasks ) {
128- if (closed ) {
129- throw new RejectedExecutionException ("Closed" );
130- }
131125 if (currentExecutor == null ) {
132126 currentExecutor = executor ;
133127 try {
@@ -161,18 +155,15 @@ public final static class CloseResult {
161155 private final Runnable activeTask ;
162156 private final List <Runnable > suspendedTasks ;
163157 private final List <Thread > suspendedThreads ;
164- private final List <Runnable > pendingTasks ;
165158
166159 private CloseResult (Thread activeThread ,
167160 Runnable activeTask ,
168161 List <Thread > suspendedThreads ,
169- List <Runnable > suspendedTasks ,
170- List <Runnable > pendingTasks ) {
162+ List <Runnable > suspendedTasks ) {
171163 this .activeThread = activeThread ;
172164 this .activeTask = activeTask ;
173165 this .suspendedThreads = suspendedThreads ;
174166 this .suspendedTasks = suspendedTasks ;
175- this .pendingTasks = pendingTasks ;
176167 }
177168
178169 /**
@@ -186,13 +177,6 @@ public Runnable activeTask() {
186177 return activeTask ;
187178 }
188179
189- /**
190- * @return the list of pending tasks
191- */
192- public List <Runnable > pendingTasks () {
193- return pendingTasks ;
194- }
195-
196180 /**
197181 * @return the list of suspended threads
198182 */
@@ -214,7 +198,6 @@ public List<Runnable> suspendedTasks() {
214198 * @return a structure of suspended threads and pending tasks
215199 */
216200 public CloseResult close () {
217- List <Runnable > pendingTasks = Collections .emptyList ();
218201 List <Thread > suspendedThreads ;
219202 List <Runnable > suspendedTasks ;
220203 Thread activeThread ;
@@ -225,19 +208,16 @@ public CloseResult close() {
225208 }
226209 suspendedThreads = new ArrayList <>(continuations .size ());
227210 suspendedTasks = new ArrayList <>(continuations .size ());
228- for (Task t : tasks ) {
229- if (t instanceof ExecuteTask ) {
230- if (pendingTasks .isEmpty ()) {
231- pendingTasks = new LinkedList <>();
232- }
233- pendingTasks .add (((ExecuteTask )t ).runnable );
234- } else if (t instanceof ContinuationTask ) {
235- ContinuationTask rt = (ContinuationTask ) t ;
236- suspendedThreads .add (rt .thread );
237- suspendedTasks .add (rt .task .runnable );
211+ Iterator <Task > it = tasks .iterator ();
212+ while (it .hasNext ()) {
213+ Task task = it .next ();
214+ if (task instanceof ContinuationTask ) {
215+ ContinuationTask continuationTask = (ContinuationTask ) task ;
216+ suspendedThreads .add (continuationTask .thread );
217+ suspendedTasks .add (continuationTask .task .runnable );
218+ it .remove ();
238219 }
239220 }
240- tasks .clear ();
241221 for (ContinuationTask cont : continuations ) {
242222 suspendedThreads .add (cont .thread );
243223 suspendedTasks .add (cont .task .runnable );
@@ -248,7 +228,7 @@ public CloseResult close() {
248228 currentExecutor = null ;
249229 closed = true ;
250230 }
251- return new CloseResult (activeThread , activeTask , suspendedThreads , suspendedTasks , pendingTasks );
231+ return new CloseResult (activeThread , activeTask , suspendedThreads , suspendedTasks );
252232 }
253233
254234 private class ContinuationTask extends CountDownLatch implements WorkerExecutor .Continuation , Task {
0 commit comments