Are Spring singleton beans thread-safe?

No. The two concepts are not even related.

Singletons are about creation. This design pattern ensures that only one instance of a class is created.

Thread safety is about execution. To quote Wikipedia:

A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same time.

So eventually thread safety depends on the code and the code only. And this is the reason why Spring beans are not thread safe per se.

Leave a Comment