Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does spring initialize beans in parallel?

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.

like image 351
ishan3243 Avatar asked Oct 18 '22 17:10

ishan3243


1 Answers

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!

like image 139
agentgonzo Avatar answered Oct 21 '22 22:10

agentgonzo