@@ -625,10 +625,13 @@ private void implJoin(Duration timeout)
625
625
}
626
626
627
627
/**
628
- * Wait for all threads in this task scope to finish or the task scope to shut down.
629
- * This method waits until all threads started in this task scope finish execution,
630
- * the {@link #shutdown() shutdown} method is invoked to shut down the task scope,
631
- * or the current thread is {@linkplain Thread#interrupt() interrupted}.
628
+ * Wait for all subtasks started in this task scope to finish or the task scope to
629
+ * shut down.
630
+ *
631
+ * <p> This method waits for all subtasks by waiting for all threads {@linkplain
632
+ * #fork(Callable) started} in this task scope to finish execution. It stops waiting
633
+ * when all threads finish, the task scope is {@linkplain #shutdown() shut down}, or
634
+ * the current thread is {@linkplain Thread#interrupt() interrupted}.
632
635
*
633
636
* <p> This method may only be invoked by the task scope owner.
634
637
*
@@ -652,11 +655,14 @@ public StructuredTaskScope<T> join() throws InterruptedException {
652
655
}
653
656
654
657
/**
655
- * Wait for all threads in this task scope to finish or the task scope to shut down,
656
- * up to the given deadline. This method waits until all threads started in the task
657
- * scope finish execution, the {@link #shutdown() shutdown} method is invoked to
658
- * shut down the task scope, the current thread is {@linkplain Thread#interrupt()
659
- * interrupted}, or the deadline is reached.
658
+ * Wait for all subtasks started in this task scope to finish or the task scope to
659
+ * shut down, up to the given deadline.
660
+ *
661
+ * <p> This method waits for all subtasks by waiting for all threads {@linkplain
662
+ * #fork(Callable) started} in this task scope to finish execution. It stops waiting
663
+ * when all threads finish, the task scope is {@linkplain #shutdown() shut down}, the
664
+ * deadline is reached, or the current thread is {@linkplain Thread#interrupt()
665
+ * interrupted}.
660
666
*
661
667
* <p> This method may only be invoked by the task scope owner.
662
668
*
@@ -950,21 +956,25 @@ public String toString() {
950
956
yield "[Failed: " + ex + "]" ;
951
957
}
952
958
};
953
- return Objects .toIdentityString (this ) + stateAsString ;
959
+ return Objects .toIdentityString (this ) + stateAsString ;
954
960
}
955
961
}
956
962
957
963
/**
958
964
* A {@code StructuredTaskScope} that captures the result of the first subtask to
959
965
* complete {@linkplain Subtask.State#SUCCESS successfully}. Once captured, it
960
- * invokes the {@linkplain #shutdown() shutdown} method to interrupt unfinished threads
966
+ * {@linkplain #shutdown() shuts down} the task scope to interrupt unfinished threads
961
967
* and wakeup the task scope owner. The policy implemented by this class is intended
962
968
* for cases where the result of any subtask will do ("invoke any") and where the
963
969
* results of other unfinished subtasks are no longer needed.
964
970
*
965
971
* <p> Unless otherwise specified, passing a {@code null} argument to a method
966
972
* in this class will cause a {@link NullPointerException} to be thrown.
967
973
*
974
+ * @apiNote This class implements a policy to shut down the task scope when a subtask
975
+ * completes successfully. There shouldn't be any need to directly shut down the task
976
+ * scope with the {@link #shutdown() shutdown} method.
977
+ *
968
978
* @param <T> the result type
969
979
* @since 21
970
980
*/
@@ -1017,8 +1027,6 @@ public ShutdownOnSuccess() {
1017
1027
1018
1028
@ Override
1019
1029
protected void handleComplete (Subtask <? extends T > subtask ) {
1020
- super .handleComplete (subtask );
1021
-
1022
1030
if (firstResult != null ) {
1023
1031
// already captured a result
1024
1032
return ;
@@ -1038,8 +1046,18 @@ protected void handleComplete(Subtask<? extends T> subtask) {
1038
1046
}
1039
1047
1040
1048
/**
1041
- * {@inheritDoc}
1042
- * @return this task scope
1049
+ * Wait for a subtask started in this task scope to complete {@linkplain
1050
+ * Subtask.State#SUCCESS successfully} or all subtasks to complete.
1051
+ *
1052
+ * <p> This method waits for all subtasks by waiting for all threads {@linkplain
1053
+ * #fork(Callable) started} in this task scope to finish execution. It stops waiting
1054
+ * when all threads finish, a subtask completes successfully, or the current
1055
+ * thread is {@linkplain Thread#interrupt() interrupted}. It also stops waiting
1056
+ * if the {@link #shutdown() shutdown} method is invoked directly to shut down
1057
+ * this task scope.
1058
+ *
1059
+ * <p> This method may only be invoked by the task scope owner.
1060
+ *
1043
1061
* @throws IllegalStateException {@inheritDoc}
1044
1062
* @throws WrongThreadException {@inheritDoc}
1045
1063
*/
@@ -1050,8 +1068,19 @@ public ShutdownOnSuccess<T> join() throws InterruptedException {
1050
1068
}
1051
1069
1052
1070
/**
1053
- * {@inheritDoc}
1054
- * @return this task scope
1071
+ * Wait for a subtask started in this task scope to complete {@linkplain
1072
+ * Subtask.State#SUCCESS successfully} or all subtasks to complete, up to the
1073
+ * given deadline.
1074
+ *
1075
+ * <p> This method waits for all subtasks by waiting for all threads {@linkplain
1076
+ * #fork(Callable) started} in this task scope to finish execution. It stops waiting
1077
+ * when all threads finish, a subtask completes successfully, the deadline is
1078
+ * reached, or the current thread is {@linkplain Thread#interrupt() interrupted}.
1079
+ * It also stops waiting if the {@link #shutdown() shutdown} method is invoked
1080
+ * directly to shut down this task scope.
1081
+ *
1082
+ * <p> This method may only be invoked by the task scope owner.
1083
+ *
1055
1084
* @throws IllegalStateException {@inheritDoc}
1056
1085
* @throws WrongThreadException {@inheritDoc}
1057
1086
*/
@@ -1073,8 +1102,8 @@ public ShutdownOnSuccess<T> joinUntil(Instant deadline)
1073
1102
*
1074
1103
* @throws ExecutionException if no subtasks completed successfully but at least
1075
1104
* one subtask failed
1076
- * @throws IllegalStateException if the handleComplete method was not invoked with
1077
- * a completed subtask, or the task scope owner did not join after forking
1105
+ * @throws IllegalStateException if no subtasks completed or the task scope owner
1106
+ * did not join after forking
1078
1107
* @throws WrongThreadException if the current thread is not the task scope owner
1079
1108
*/
1080
1109
public T result () throws ExecutionException {
@@ -1095,8 +1124,8 @@ public T result() throws ExecutionException {
1095
1124
* @return the result of the first subtask that completed with a result
1096
1125
*
1097
1126
* @throws X if no subtasks completed successfully but at least one subtask failed
1098
- * @throws IllegalStateException if the handleComplete method was not invoked with
1099
- * a completed subtask, or the task scope owner did not join after forking
1127
+ * @throws IllegalStateException if no subtasks completed or the task scope owner
1128
+ * did not join after forking
1100
1129
* @throws WrongThreadException if the current thread is not the task scope owner
1101
1130
*/
1102
1131
public <X extends Throwable > T result (Function <Throwable , ? extends X > esf ) throws X {
@@ -1125,15 +1154,19 @@ public <X extends Throwable> T result(Function<Throwable, ? extends X> esf) thro
1125
1154
1126
1155
/**
1127
1156
* A {@code StructuredTaskScope} that captures the exception of the first subtask to
1128
- * {@linkplain Subtask.State#FAILED fail}. Once captured, it invokes the {@linkplain
1129
- * #shutdown() shutdown} method to interrupt unfinished threads and wakeup the task
1157
+ * {@linkplain Subtask.State#FAILED fail}. Once captured, it {@linkplain #shutdown()
1158
+ * shuts down} the task scope to interrupt unfinished threads and wakeup the task
1130
1159
* scope owner. The policy implemented by this class is intended for cases where the
1131
1160
* results for all subtasks are required ("invoke all"); if any subtask fails then the
1132
1161
* results of other unfinished subtasks are no longer needed.
1133
1162
*
1134
1163
* <p> Unless otherwise specified, passing a {@code null} argument to a method
1135
1164
* in this class will cause a {@link NullPointerException} to be thrown.
1136
1165
*
1166
+ * @apiNote This class implements a policy to shut down the task scope when a subtask
1167
+ * fails. There shouldn't be any need to directly shut down the task scope with the
1168
+ * {@link #shutdown() shutdown} method.
1169
+ *
1137
1170
* @since 21
1138
1171
*/
1139
1172
@ PreviewFeature (feature = PreviewFeature .Feature .STRUCTURED_CONCURRENCY )
@@ -1181,7 +1214,6 @@ public ShutdownOnFailure() {
1181
1214
1182
1215
@ Override
1183
1216
protected void handleComplete (Subtask <?> subtask ) {
1184
- super .handleComplete (subtask );
1185
1217
if (subtask .state () == Subtask .State .FAILED
1186
1218
&& firstException == null
1187
1219
&& FIRST_EXCEPTION .compareAndSet (this , null , subtask .exception ())) {
@@ -1190,8 +1222,17 @@ protected void handleComplete(Subtask<?> subtask) {
1190
1222
}
1191
1223
1192
1224
/**
1193
- * {@inheritDoc}
1194
- * @return this task scope
1225
+ * Wait for all subtasks started in this task scope to complete or for a subtask
1226
+ * to {@linkplain Subtask.State#FAILED fail}.
1227
+ *
1228
+ * <p> This method waits for all subtasks by waiting for all threads {@linkplain
1229
+ * #fork(Callable) started} in this task scope to finish execution. It stops waiting
1230
+ * when all threads finish, a subtask fails, or the current thread is {@linkplain
1231
+ * Thread#interrupt() interrupted}. It also stops waiting if the {@link #shutdown()
1232
+ * shutdown} method is invoked directly to shut down this task scope.
1233
+ *
1234
+ * <p> This method may only be invoked by the task scope owner.
1235
+ *
1195
1236
* @throws IllegalStateException {@inheritDoc}
1196
1237
* @throws WrongThreadException {@inheritDoc}
1197
1238
*/
@@ -1202,8 +1243,18 @@ public ShutdownOnFailure join() throws InterruptedException {
1202
1243
}
1203
1244
1204
1245
/**
1205
- * {@inheritDoc}
1206
- * @return this task scope
1246
+ * Wait for all subtasks started in this task scope to complete or for a subtask
1247
+ * to {@linkplain Subtask.State#FAILED fail}, up to the given deadline.
1248
+ *
1249
+ * <p> This method waits for all subtasks by waiting for all threads {@linkplain
1250
+ * #fork(Callable) started} in this task scope to finish execution. It stops waiting
1251
+ * when all threads finish, a subtask fails, the deadline is reached, or the current
1252
+ * thread is {@linkplain Thread#interrupt() interrupted}. It also stops waiting
1253
+ * if the {@link #shutdown() shutdown} method is invoked directly to shut down
1254
+ * this task scope.
1255
+ *
1256
+ * <p> This method may only be invoked by the task scope owner.
1257
+ *
1207
1258
* @throws IllegalStateException {@inheritDoc}
1208
1259
* @throws WrongThreadException {@inheritDoc}
1209
1260
*/
0 commit comments