6

I have a lot of independent spring beans in my project (classes annotated with @Component -- NOT lazily initialized). I wanted to know weather the beans will be initialized serially or parallely? I am asking this because the beans modify a common data structure on initialization and I wanted to know weather the data structure should be made thread-safe.

Spring version used:- 4.2

I was reading open issues on spring jira website:-

According to https://jira.spring.io/browse/SPR-9887 it seems to be parallely initialized

But according to https://jira.spring.io/browse/SPR-8767 it seems to be serially initialized.

ishan3243
  • 1,870
  • 4
  • 30
  • 49
  • 3
    Read again. The request is to do it parallel currently it is serial. So no nothing is done in parallel, none-the-less making things thread safe is always a good thing. Also the issue is regarding component-scanning which is something different them initializing/creating beans. Although they are related. – M. Deinum Jan 28 '16 at 12:30

1 Answers1

4

Spring initialises beans in serial. There is nothing that says that they are initialised in parallel. In fact, the ticket that you cite (https://jira.spring.io/browse/SPR-9887) is a closed ticket because it's a duplicate of https://jira.spring.io/browse/SPR-8767. This ticket is unresolved and targetted for the release of spring 5.0 in the future, so nothing says that beans are initialised in parallel!

agentgonzo
  • 3,473
  • 3
  • 25
  • 30
  • 1
    Starting in 4.3 Spring processes JPA/Hibernate in the background during startup, so at least there's some parallelization now. https://jira.spring.io/browse/SPR-13732 – Matt Sgarlata Jun 30 '17 at 15:19