J.IX · Java 25 practice question

A framework binds a request ID to a ScopedValue using run and then invokes application code. When does that binding expire?

Choose one answer
Check answer and explanation

Correct answer: As soon as the run method call completes

Explanation

A scoped value passed to run remains bound only for the lifetime of that run call, so the binding ends automatically as soon as the run method call completes.

Common trap

Developers used to ThreadLocal expect bindings to persist for the entire thread lifetime unless explicitly cleared, but scoped values are strictly bounded to the run call. Reading a scoped value with get() does not consume or unbind it; any number of methods invoked during run can read it.

Source: JEP 506: Scoped Values — Description
Checked against the cited text on 2026-11-25.

Report an error in this question