简体   繁体   中英

Are methods in a Singleton class thread safe?

Is Concurrent method access in singleton class thread safe?

I am using Spring framework (MVC) with the default scope as Singleton.

For example, if the controller of my web application is a Singleton class, are the methods declared to access Model/Business/DB classes thread safe, if accessed by multiple threads at the same time? How about calls to DB for database access/update from these methods in the Controller?

Need guidance and I aprreciate any help/suggestions for this issue.

No, Singleton does not guarantee thread safety. You have to manage that yourself.

The best way to do it is to make Singleton's stateless. If there's no shared state you're fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM