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 |
|
/** |
1037 |
|
.pollTask(); |
1038 |
|
} |
1039 |
|
|
1040 |
+ |
// adaptors |
1041 |
+ |
|
1042 |
+ |
/** |
1043 |
+ |
* Returns a new ForkJoinTask that performs the <code>run</code> |
1044 |
+ |
* method of the given Runnable as its action, and returns a null |
1045 |
+ |
* result upon <code>join</code>. |
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</code> |
1056 |
+ |
* method of the given Runnable as its action, and returns the |
1057 |
+ |
* given result upon <code>join</code>. |
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</code> |
1069 |
+ |
* method of the given Callable as its action, and returns its |
1070 |
+ |
* result upon <code>join</code>, translating any checked |
1071 |
+ |
* exceptions encountered into <code>RuntimeException<code>. |
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; |