How does Spring bean Handle concurrency

前端 未结 4 1686
栀梦
栀梦 2020-12-13 03:16

My web application uses Spring IOC. So all my spring beans will be singletons by default. In case if two requests try to access two different methods of a single class (for

4条回答
  •  醉梦人生
    2020-12-13 03:33

    You must first understand when concurrency can cause problems. If your Spring bean is stateless (it doesn't have any fields, all fields are final or all of them are assigned only once), multiple threads can safely use the same bean, or even the same method.

    See also:

    • thread safe, stateless design using Spring
    • spring mvc declaring all beans singleton

提交回复
热议问题