Interface StructuredTaskScope.Configuration
- Enclosing interface:
StructuredTaskScopePREVIEW<T,R>
public static sealed interface StructuredTaskScope.Configuration
Configuration is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Represents the configuration for a
StructuredTaskScope.
The configuration for a StructuredTaskScope consists of a ThreadFactory to create threads, an optional name for the scope, and an optional
timeout. The name is intended for monitoring and management purposes.
Creating a StructuredTaskScope with its 2-arg openPREVIEW method allows a different configuration to be used. The operator specified
to the open method is applied to the default configuration and returns the
configuration for the StructuredTaskScope under construction. The operator
can use the with- prefixed methods defined here to specify the components
of the configuration to use.
Unless otherwise specified, passing a null argument to a method
in this class will cause a NullPointerException to be thrown.
- Since:
- 25
-
Method Summary
Modifier and TypeMethodDescriptionReturns a newConfigurationobject with the given scope name.withThreadFactory(ThreadFactory threadFactory) Returns a newConfigurationobject with the given thread factory.withTimeout(Duration timeout) Returns a newConfigurationobject with the given timeout.
-
Method Details
-
withThreadFactory
Returns a newConfigurationobject with the given thread factory. The other components are the same as this object. The thread factory is used by a scope to create threads when forkingPREVIEW subtasks.- API Note:
- The thread factory will typically create virtual threads, maybe with names for monitoring purposes, an uncaught exception handler, or other properties configured.
- Parameters:
threadFactory- the thread factory- Returns:
- a new
Configurationobject with the given thread factory - See Also:
-
withName
Returns a newConfigurationobject with the given scope name. The other components are the same as this object. A scope is optionally named for the purposes of monitoring and management.- Parameters:
name- the name- Returns:
- a new
Configurationobject with the given scope name
-
withTimeout
Returns a newConfigurationobject with the given timeout. The other components are the same as this object.- API Note:
- Applications using deadlines, expressed as an
Instant, can useDuration.between(Instant.now(), deadline)to compute the timeout for this method. - Parameters:
timeout- the timeout- Returns:
- a new
Configurationobject with the given timeout - See Also:
-
Configurationwhen preview features are enabled.