Interface StructuredTaskScope.Subtask<T>
- Type Parameters:
T
- the result type
- All Superinterfaces:
Supplier<T>
- Enclosing interface:
StructuredTaskScopePREVIEW<T,
R>
Subtask
is a preview API of the Java platform.
StructuredTaskScope.fork(Callable)
PREVIEW or StructuredTaskScope.fork(Runnable)
PREVIEW.
Code that forks subtasks 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
Modifier and TypeInterfaceDescriptionstatic enum
Preview.Represents the state of a subtask. -
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 forkedPREVIEW to execute a value-returning task then the result from thecall
method is returned. If forkedPREVIEW to execute a task that does not return a result thennull
is returned.Code executing in the scope owner thread can use this method to get the result of a successful subtask only after it has joinedPREVIEW.
Code executing in the
Joiner
onComplete
PREVIEW method should test that the subtask state isSUCCESS
PREVIEW before using this method to get the result. -
exception
Throwable exception()Returns the exception thrown by this subtask if it failed. If forkedPREVIEW to execute a value-returning task then the exception thrown by thecall
method is returned. If forkedPREVIEW to execute a task that does not return a result then the exception 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 only after it has joinedPREVIEW.
Code executing in a
Joiner
onComplete
PREVIEW method should test that the subtask state isFAILED
PREVIEW before using this method to get the exception.- Returns:
- the exception thrown by this subtask if it failed
- Throws:
IllegalStateException
- if the subtask has not completed, completed with a result, or the current thread is the scope owner invoking this method before joiningPREVIEW- See Also:
-
Subtask
when preview features are enabled.