The same idea on Java 17: a request-scoped value with a ThreadLocal
Structured concurrency (preview in Java 21 to 25) treats a group of related subtasks as one unit: they start in a scope, finish or fail together, and are cancelled together. Scoped values (final in Java 25) share read-only data with everything a task calls, a safer replacement for ThreadLocal.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write (for JDK 25) a scoped value REQUEST_ID and a method log(String msg) that prints the request id with every message; bind it for two different requests.
Explain it without notes
What problem does structured concurrency solve?
How are scoped values better than ThreadLocal?
Expected output
handling request for asha
after: null