I’ve tried hard to find any material on best practices regarding thread-safety in Spring, in the Reference Documentation, in this forum and out in the wild, but I don’t get the picture. The message seems to be “use the singleton scope and make sure your beans are thread-safe”.
I’m thinking about highly concurrent applications with a web UI, some JMS queues and scheduled tasks on top. If all services are singletons and if Spring cannot guarantee thread-safety, then any service class with any instance variables not injected by Spring is a potential risk.
Making a class thread-safe is not trivial. Most third-party classes do not even document whether or not they are thread-safe, so you have to assume they are not thread-safe and synchronize them manually or spend a lot of time reviewing the sources to convince yourself they are thread-safe.
That doesn’t sound like a smart solution.
If there is a better approach, then the Reference Documentation should dedicate a section to it. If there is none, I’d rather not use Spring…