QuizzesStructured Concurrency — Concept Check
intermediate
java

Structured Concurrency — Concept Check

Questions on Structured Concurrency. Structured Concurrency (Java 21) scopes subtask lifetimes to their parent, preventing thread leaks and simplifying error handling in concurrent code.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Structured Concurrency — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer uses ShutdownOnFailure in a StructuredTaskScope. What happens if one subtask fails?

    • AOnly the failed subtask is cancelled, others continue.
    • BThe failed subtask restarts automatically.
    • CThe scope ignores the failure and continues.
    • DAll subtasks are cancelled and the exception is propagated.
  2. 2.You have a task that fetches data from multiple sources using ShutdownOnSuccess. What happens if the first source succeeds?

    • AThe other subtasks are cancelled.
    • BThe scope throws an exception.
    • CThe scope waits for all subtasks to complete.
    • DAll subtasks continue to run.
  3. 3.In a StructuredTaskScope, what guarantees are provided when the try block exits?

    • AAll forked tasks are complete or cancelled.
    • BTasks are paused until re-entering the scope.
    • COnly failed tasks are cancelled.
    • DSome tasks may still be running.
  4. 4.A developer uses CompletableFuture for concurrent tasks but forgets manual cancellation. What issue might arise?

    • AThread leaks due to indefinite task execution.
    • BImmediate task completion on failure.
    • CTasks are paused until manually resumed.
    • DAutomatic task cancellation by default.
  5. 5.What is a key benefit of using Structured Concurrency over CompletableFuture?

    • ASimpler syntax for asynchronous tasks.
    • BAutomatic subtask lifetime management.
    • CImproved performance through parallelism.
    • DBuilt-in support for distributed computing.
  6. 6.When using StructuredTaskScope, how should subtasks be initiated?

    • ABy manually creating new threads.
    • BUsing a separate executor service.
    • CDirectly calling the task's run method.
    • DUsing scope.fork() within a try-with-resources block.
  7. 7.A service uses Structured Concurrency to fetch user data. If the user fetch fails, what happens to the order fetch?

    • AThe order fetch is paused.
    • BThe order fetch continues independently.
    • CThe order fetch restarts automatically.
    • DThe order fetch is cancelled.
  8. 8.What is the role of scope.join() in StructuredTaskScope?

    • AStarts all forked subtasks.
    • BWaits for all subtasks to complete.
    • CIgnores failed subtasks.
    • DCancels all running subtasks.