23 February 2020

Singleton Spring

Singleton Spring Beans are not like the GoF Singleton design pattern.

 Spring can have more than one if they have different id's; meanwhile, GoF only allows one instance of the class (object) in the complete classloader.

 None option can solve some thread-safe issues that may appear by the composition of other objects that are nor thread-safe, JDBC connections, HTTP session, SimpleDateFormat, etc.

Update:

From that URL:

Summary

Spring Singleton is very different from Singleton pattern. Spring guarantees to create only one bean instance for given bean id definition per container.Singleton pattern ensures that one and only one instance is created per ClassLoader.


Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.