Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardJavaThreadLocal lifecycle leaksSingle-choice MCQ

A parent thread sets an InheritableThreadLocal, then spawns a child thread. The parent later updates the same InheritableThreadLocal value. What does the child observe, and why?

static InheritableThreadLocal<List<String>> ctx = new InheritableThreadLocal<>(); ctx.set(new ArrayList<>(List.of("a"))); Thread child = new Thread(() -> { /* reads ctx.get() */ }); child.start(); ctx.set(new ArrayList<>(List.of("b"))); // parent updates after start