Ad (728x90)

Filled Under: ,

Is spring provide thread-safety?

spring Spring Interview Questions
I used to work in environments where the container guarantees thread-safety, i.e. each instance of an application class is always run by at most one thread at a time.

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...

Unknown

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comments:

Post a Comment

Please write to us here...

 

We are featured contributor on entrepreneurship for many trusted business sites:

  • Copyright © Tekhnologia™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Templates.