0 votes
in Spring by

Does Spring Bean provide thread safety?

1 Answer

0 votes
by
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.

Related questions

0 votes
asked Jul 27, 2020 in Spring by Robindeniel
0 votes
asked Jul 26, 2020 in Spring by SakshiSharma
...