Interface StructuredTaskScope.Subtask<T>
- Type Parameters:
T- the result type
- All Superinterfaces:
Supplier<T>
Subtask is a preview API of the Java platform.
StructuredTaskScopePREVIEW with fork(Callable)PREVIEW or fork(Runnable)PREVIEW.
The scope owner can use the get() method after joiningPREVIEW to obtain the result of a subtask that completed successfully. It
can use the exception() method to obtain the exception thrown by a subtask
that failed.
- Since:
- 21
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum -
Method Summary
-
Method Details
-
state
Returns the subtask state.- Returns:
- the subtask state
-
get
T get()Returns the result of this subtask if it completed successfully. If the scope is cancelled, the subtask completed successfully before the scope was cancelled. If the subtask was forked withfork(Callable)PREVIEW then the result from thecall()method is returned. If the subtask was forked withfork(Runnable)PREVIEW thennullis returned.Code executing in the scope owner thread can use this method to get the result of a successful subtask after it has joinedPREVIEW.
Code executing in the
JoineronComplete(Subtask)PREVIEW method should test that the state isSUCCESSPREVIEW before using this method to get the result.This method may be invoked by any thread after the scope owner has joined. The only case where this method can be used to get the result before the scope owner has joined is when called from the
onComplete(Subtask)method.- Specified by:
getin interfaceSupplier<T>- Returns:
- the possibly-null result
- Throws:
IllegalStateException- if the subtask has not completed or did not complete successfully, or this method is invoked outside the context of theonComplete(Subtask)method before the owner thread has joined- See Also:
-
exception
Throwable exception()Returns the exception or error thrown by this subtask if it failed. If the scope is cancelled, the subtask failed before the scope was cancelled. If the subtask was forked withfork(Callable)PREVIEW then the exception or error thrown by thecall()method is returned. If the subtask was forked withfork(Runnable)PREVIEW then the exception or error thrown by therun()method is returned.Code executing in the scope owner thread can use this method to get the exception thrown by a failed subtask after it has joinedPREVIEW.
Code executing in a
JoineronComplete(Subtask)PREVIEW method should test that the state isFAILEDPREVIEW before using this method to get the exception.This method may be invoked by any thread after the scope owner has joined. The only case where this method can be used to get the exception before the scope owner has joined is when called from the
onComplete(Subtask)method.- Returns:
- the exception or error thrown by this subtask if it failed
- Throws:
IllegalStateException- if the subtask has not completed or completed with a result, or this method is invoked outside the context of theonComplete(Subtask)method before the owner thread has joined- See Also:
-
Subtaskwhen preview features are enabled.