How does the singleton Bean serve the concurrent request?

后端 未结 6 1839
情话喂你
情话喂你 2020-12-07 07:57

I have a question regarding how singleton beans serve concurrent requests in detail.

I have searched on StackOverflow regarding this question. This is a sample link

6条回答
  •  粉色の甜心
    2020-12-07 08:51

    To know in details How does the singleton Bean serve the concurrent request? you have to know the following things about Spring Beans

    • Bean scopes

      Spring has different bean scopes (e.g. Prototype, Singleton, etc.) but all these scopes enforce is when the bean is created. For example a "prototype" scoped bean will be created each time this bean is "injected". whereas a "singleton" scoped bean will be created once and shared within the application context.
      "singleton" scoped is default scope of Spring Bean.

    • Creation of Bean

      The whole life cycle of Spring Bean is managed by the Spring Container (i.e. ApplicationContext/BeanFacotry) Spring Container internally refers the bean definition (i.e.XML base ot Annotation based) for creating actual instances of the class defined by that bean definition. now when Spring Container get started it refers to the bean definition and instatiate all the defined bean.

    • Request the Bean.

      Now when your object make a request to the bean then Spring Container will handover the bean which allready initialized.

    • Spring Bean Scope

    • Are Spring objects thread safe?

    • Spring Tutorial 11 - Understanding Bean Scopes

    hope this will help you...

提交回复
热议问题