490 |
|
* computations (as may be determined using method {@link |
491 |
|
* #inForkJoinPool}). Attempts to invoke in other contexts result |
492 |
|
* in exceptions or errors, possibly including ClassCastException. |
493 |
+ |
* |
494 |
+ |
* @return {@code this}, to simplify usage. |
495 |
|
*/ |
496 |
< |
public final void fork() { |
496 |
> |
public final ForkJoinTask<V> fork() { |
497 |
|
((ForkJoinWorkerThread) Thread.currentThread()) |
498 |
|
.pushTask(this); |
499 |
+ |
return this; |
500 |
|
} |
501 |
|
|
502 |
|
/** |
604 |
|
* in exceptions or errors, possibly including ClassCastException. |
605 |
|
* |
606 |
|
* @param tasks the collection of tasks |
607 |
+ |
* @return the tasks argument, to simplify usage |
608 |
|
* @throws NullPointerException if tasks or any element are null |
609 |
|
* @throws RuntimeException or Error if any task did so |
610 |
|
*/ |
611 |
< |
public static void invokeAll(Collection<? extends ForkJoinTask<?>> tasks) { |
611 |
> |
public static <T extends ForkJoinTask<?>> Collection<T> invokeAll(Collection<T> tasks) { |
612 |
|
if (!(tasks instanceof List<?>)) { |
613 |
|
invokeAll(tasks.toArray(new ForkJoinTask<?>[tasks.size()])); |
614 |
< |
return; |
614 |
> |
return tasks; |
615 |
|
} |
616 |
|
@SuppressWarnings("unchecked") |
617 |
|
List<? extends ForkJoinTask<?>> ts = |
646 |
|
} |
647 |
|
if (ex != null) |
648 |
|
rethrowException(ex); |
649 |
+ |
return tasks; |
650 |
|
} |
651 |
|
|
652 |
|
/** |
1037 |
|
.pollTask(); |
1038 |
|
} |
1039 |
|
|
1040 |
+ |
// adaptors |
1041 |
+ |
|
1042 |
+ |
/** |
1043 |
+ |
* Returns a new ForkJoinTask that performs the {@code run} |
1044 |
+ |
* method of the given Runnable as its action, and returns a null |
1045 |
+ |
* result upon {@code join}. |
1046 |
+ |
* |
1047 |
+ |
* @param runnable the runnable action |
1048 |
+ |
* @return the task |
1049 |
+ |
*/ |
1050 |
+ |
public static ForkJoinTask<Void> adapt(Runnable runnable) { |
1051 |
+ |
return new ForkJoinPool.AdaptedRunnable<Void>(runnable, null); |
1052 |
+ |
} |
1053 |
+ |
|
1054 |
+ |
/** |
1055 |
+ |
* Returns a new ForkJoinTask that performs the {@code run} |
1056 |
+ |
* method of the given Runnable as its action, and returns the |
1057 |
+ |
* given result upon {@code join}. |
1058 |
+ |
* |
1059 |
+ |
* @param runnable the runnable action |
1060 |
+ |
* @param result the result upon completion |
1061 |
+ |
* @return the task |
1062 |
+ |
*/ |
1063 |
+ |
public static <T> ForkJoinTask<T> adapt(Runnable runnable, T result) { |
1064 |
+ |
return new ForkJoinPool.AdaptedRunnable<T>(runnable, result); |
1065 |
+ |
} |
1066 |
+ |
|
1067 |
+ |
/** |
1068 |
+ |
* Returns a new ForkJoinTask that performs the {@code call} |
1069 |
+ |
* method of the given Callable as its action, and returns its |
1070 |
+ |
* result upon {@code join}, translating any checked |
1071 |
+ |
* exceptions encountered into {@code RuntimeException}. |
1072 |
+ |
* |
1073 |
+ |
* @param callable the callable action |
1074 |
+ |
* @return the task |
1075 |
+ |
*/ |
1076 |
+ |
public static <T> ForkJoinTask<T> adapt(Callable<T> callable) { |
1077 |
+ |
return new ForkJoinPool.AdaptedCallable<T>(callable); |
1078 |
+ |
} |
1079 |
+ |
|
1080 |
|
// Serialization support |
1081 |
|
|
1082 |
|
private static final long serialVersionUID = -7721805057305804111L; |
1123 |
|
} |
1124 |
|
|
1125 |
|
private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe(); |
1126 |
< |
static final long statusOffset = |
1126 |
> |
private static final long statusOffset = |
1127 |
|
fieldOffset("status", ForkJoinTask.class); |
1128 |
|
|
1129 |
|
} |