Spec-Zone.ru › OpenJDK 27

Interface StructuredTaskScope.Subtask<T>

Type Parameters:
T - the result type
All Superinterfaces:
Supplier<T>
Enclosing interface:
StructuredTaskScopePREVIEW<T, R, R_X extends Throwable>
public static sealed interface StructuredTaskScope.Subtask<T> extends Supplier<T>
Subtask is a preview API of the Java platform.
Programs can only use Subtask when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Represents a subtask forked in a 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

Modifier and Type Interface Description
static enum  StructuredTaskScope.Subtask.StatePREVIEW
Preview.
Represents the state of a SubtaskPREVIEW.

Method Summary

Modifier and Type Method Description
Throwable exception()
Returns the exception or error thrown by this subtask if it failed.
T get()
Returns the result of this subtask if it completed successfully.
StructuredTaskScope.Subtask.StatePREVIEW state()
Returns the subtask state.

Method Details

state

StructuredTaskScope.Subtask.StatePREVIEW 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 with fork(Callable)PREVIEW then the result from the call() method is returned. If the subtask was forked with fork(Runnable)PREVIEW then null is 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 Joiner onComplete(Subtask)PREVIEW method should test that the state is SUCCESSPREVIEW 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:
get in interface Supplier<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 the onComplete(Subtask) method before the owner thread has joined
See Also:
  • StructuredTaskScope.Subtask.State.SUCCESSPREVIEW

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 with fork(Callable)PREVIEW then the exception or error thrown by the call() method is returned. If the subtask was forked with fork(Runnable)PREVIEW then the exception or error thrown by the run() 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 Joiner onComplete(Subtask)PREVIEW method should test that the state is FAILEDPREVIEW 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 the onComplete(Subtask) method before the owner thread has joined
See Also:
  • StructuredTaskScope.Subtask.State.FAILEDPREVIEW

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API