Thread safety is a different context . Singleton spring beans has no relation with thread safety. spring container only manages life-cycle of objects and guaranteed that only one object in spring container. so If an Non thread safe object is injected then obviously it is not thread safe. To make it thread safe you have to handle it by coding.
If it is a web-application , Scope("request") can achieve thread-safety as for each new request it creates a new object or scope("prototype") will do this.
I am talking from web application prospective, when multiple request comes and same spring bean is accessed. If scope is prototype, new instance will be created.
No comments:
Post a Comment