Does Spring Bean provide thread safety?

Technology CommunityCategory: SpringDoes Spring Bean provide thread safety?
VietMX Staff asked 3 years ago

The default scope of Spring bean is singleton, so there will be only one instance per context. That means that all the having a class level variable that any thread can update will lead to inconsistent data. Hence in default mode spring beans are not thread-safe.

However, we can change spring bean scope to request, prototype or session to achieve thread-safety at the cost of performance. It’s a design decision and based on the project requirements.