Class StructuredTaskScope.ShutdownOnFailure

All Implemented Interfaces:
Enclosing class:

public static final class StructuredTaskScope.ShutdownOnFailure extends StructuredTaskScopePREVIEW<Object>
ShutdownOnFailure is a preview API of the Java platform.
Programs can only use ShutdownOnFailure when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A StructuredTaskScope that captures the exception of the first subtask to failPREVIEW. Once captured, it shuts downPREVIEW the task scope to interrupt unfinished threads and wakeup the task scope owner. The policy implemented by this class is intended for cases where the results for all subtasks are required ("invoke all"); if any subtask fails then the results of other unfinished subtasks are no longer needed.

Unless otherwise specified, passing a null argument to a method in this class will cause a NullPointerException to be thrown.

API Note:
This class implements a policy to shut down the task scope when a subtask fails. There shouldn't be any need to directly shut down the task scope with the shutdownPREVIEW method.
  • Constructor Details

    • ShutdownOnFailure

      public ShutdownOnFailure(String name, ThreadFactory factory)
      Constructs a new ShutdownOnFailure with the given name and thread factory. The task scope is optionally named for the purposes of monitoring and management. The thread factory is used to create threads when subtasks are forkedPREVIEW. The task scope is owned by the current thread.

      Construction captures the current thread's scoped valuePREVIEW bindings for inheritance by threads started in the task scope. The Tree Structure section in the class description details how parent-child relations are established implicitly for the purpose of inheritance of scoped value bindings.

      name - the name of the task scope, can be null
      factory - the thread factory
    • ShutdownOnFailure

      public ShutdownOnFailure()
      Constructs a new unnamed ShutdownOnFailure that creates virtual threads.
      Implementation Requirements:
      This constructor is equivalent to invoking the 2-arg constructor with a name of null and a thread factory that creates virtual threads.
  • Method Details