java - spring中bean为单例为什么有助于线程无关性
高洛峰
高洛峰 2017-04-18 09:43:46
0
3
414

怎么理解这句话:spring的bean都是单实例(singleton)的,其最大好处就是线程无关性? 我觉得如果是单实例的,那么对于某个bean,在spring容器中应该全局就一个bean实例。如果只有一个bean实例,多个线程都用它,才更会产生线程的冲突啊!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
巴扎黑

Thread-independent means that each thread will not be allocated an instance, or the generation of instances has nothing to do with threads. But thread independence does not mean thread safety. Thread safety needs to be done by yourself

左手右手慢动作

Single instance beans are all stateless, so why do thread conflicts arise? If you use a stateful bean as a single instance, there is something wrong with your own logic

刘奇

This sentence is incomplete, singleton + stateless can be thread safe

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!