I am really sorry to ask such a question, but I need a bit of your help.
As far I understand, if I use servlets all my business logic ( methods of which I call in controllers ) should be Thread-safe.
Does the same count for Spring? Do I need to make thread-safe methods in service layer when I use @Getmapping @PostMapping instead of using servlets directly?
I do appreciate your help a lot!
Thread safety is a different context .
Singleton spring beans(default scope) 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 a 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.(for each invocation it creates new bean .)
Answered By – Tarun