This is the first lecture of the seventh session of Part 1 of the [Modern Backend] course, "Context Propagation Refactoring (1)."
In this lecture, we will analyze the targets and carry out design refactoring to transition the bulletin board project's existing ThreadLocal-based context propagation logic to a Java 25 ScopedValue-based architecture.
📌 Key topics covered:
-
Review of the four files targeted for refactoring (RequestContext, RequestContextFilter, PostCreationCoordinator, etc.)
-
The five-step refactoring sequence and a compiler-error-driven approach
-
Analysis of the existing ThreadLocal code structure and identification of the four manual management points that depended on developer conventions (set/clear)
-
Converting the inside of the RequestContext holder to use ScopedValue and expanding its API methods
runWith,callWith,getOrSystemetc.) -
Replacing the web request entry point (Servlet Filter) with a Scoped Value scope-binding structure
-
Within the Servlet Filter,
runWith/callWithThe principles for resolving checked exceptions and Java type-inference compilation errors that may occur when using
Go beyond the structural limitations of the existing ThreadLocal and explore the Modern Java architecture refactoring process for safely propagating context.