mutable state
Data that can change after it is created, such as a field that is reassigned or a list that is added to.
In more detail
Mutable state is where most bugs involving ownership and concurrency live. When two threads change the same state without coordination, the result depends on timing. Prefer immutable values, give each piece of mutable state one clear owner, and keep singletons stateless.
Related terms
- immutable — Something that cannot be changed after it is created; to change it you make a new one.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
- defensive copy — A copy of a mutable object, such as a list, made when it crosses a boundary so the other side cannot change your data.
- bean scope — The rule for how many instances of a Spring bean exist: one shared singleton by default, or a new one per use, request or session.
Taught in
- The Collections Framework — Modern Java: Virtual Threads & High-Throughput Services
- Concurrency Basics: Threads And Runnable — Modern Java: Virtual Threads & High-Throughput Services
- Dependency Injection And The IoC Container — Modern Java: Virtual Threads & High-Throughput Services