ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ForkJoinPool.java
(Generate patch)

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.22 by jsr166, Sat Jul 25 00:34:00 2009 UTC vs.
Revision 1.23 by dl, Sat Jul 25 15:50:57 2009 UTC

# Line 548 | Line 548 | public class ForkJoinPool extends Abstra
548       * Common code for execute, invoke and submit
549       */
550      private <T> void doSubmit(ForkJoinTask<T> task) {
551 +        if (task == null)
552 +            throw new NullPointerException();
553          if (isShutdown())
554              throw new RejectedExecutionException();
555          if (workers == null)
# Line 583 | Line 585 | public class ForkJoinPool extends Abstra
585      // AbstractExecutorService methods
586  
587      public void execute(Runnable task) {
588 <        doSubmit(new AdaptedRunnable<Void>(task, null));
588 >        ForkJoinTask<?> job;
589 >        if (task instanceof AdaptedCallable) // avoid re-wrap
590 >            job = (AdaptedCallable<?>)task;
591 >        else if (task instanceof AdaptedRunnable)
592 >            job = (AdaptedRunnable<?>)task;
593 >        else
594 >            job = new AdaptedRunnable<Void>(task, null);
595 >        doSubmit(job);
596      }
597  
598      public <T> ForkJoinTask<T> submit(Callable<T> task) {
# Line 599 | Line 608 | public class ForkJoinPool extends Abstra
608      }
609  
610      public ForkJoinTask<?> submit(Runnable task) {
611 <        ForkJoinTask<Void> job = new AdaptedRunnable<Void>(task, null);
611 >        ForkJoinTask<?> job;
612 >        if (task instanceof AdaptedCallable) // avoid re-wrap
613 >            job = (AdaptedCallable<?>)task;
614 >        else if (task instanceof AdaptedRunnable)
615 >            job = (AdaptedRunnable<?>)task;
616 >        else
617 >            job = new AdaptedRunnable<Void>(task, null);
618          doSubmit(job);
619          return job;
620      }
621  
622      /**
623 +     * Submits a ForkJoinTask for execution.
624 +     *
625 +     * @param task the task to submit
626 +     * @return the task
627 +     * @throws RejectedExecutionException if the task cannot be
628 +     *         scheduled for execution
629 +     * @throws NullPointerException if the task is null
630 +     */
631 +    public <T> ForkJoinTask<T> submit(ForkJoinTask<T> task) {
632 +        doSubmit(task);
633 +        return task;
634 +    }
635 +
636 +    /**
637       * Adaptor for Runnables. This implements RunnableFuture
638       * to be compliant with AbstractExecutorService constraints.
639       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines