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