Description
Tomasz Nurkiewicz opened SPR-8767 and commented
Spring should provide a way (possibly a BeanFactory
with a different ConfigurableListableBeanFactory#preInstantiateSingletons
implementation) to initialize singleton non-lazy beans on startup in parallel using a thread pool. This could significantly reduce startup (and maybe shutdown) time by creating and initializing independent beans concurrently.
The algorithm is pretty simple in principle. Whereas the normal bean factory creates beans in single thread in rather random order, this implementation should:
- Find all bean definitions that don't have any unresolved dependencies.
- Schedule creation of each bean found in 1. in a separate concurrent task to allow parallel creation
- When any of the tasks scheduled in 2. is completed go to 1.
The algorithm stops when all beans are created.
Implementation notes:
- circular dependencies might require extra care
- bean factory should create a thread pool with configurable number of threads and shut it down after all beans are created
Affects: 3.1 RC1
Reference URL: http://forum.springsource.org/showthread.php?105896-Initialize-spring-beans-in-parallel-at-startup
Issue Links:
- Parallelize Component Scanning to Improve Spring Startup Time [SPR-9887] #14520 Parallelize Component Scanning to Improve Spring Startup Time ("is duplicated by")
- Threads bottlenecking in DefaultSingletonBeanRegistry when using Wicket's @SpringBean annotation for injection [SPR-5360] #10033 Threads bottlenecking in DefaultSingletonBeanRegistry when using Wicket's
@SpringBean
annotation for injection - Parallelize Component Scanning to Improve Spring Startup Time [SPR-9887] #14520 Parallelize Component Scanning to Improve Spring Startup Time
- Initialization blocked by multi-threaded event publishing [SPR-16357] #20904 Initialization blocked by multi-threaded event publishing
- Asynchronous initialization of beans during startup [SPR-14920] #19487 Asynchronous initialization of beans during startup
- Background initialization option for JPA EntityManagerFactory / Hibernate SessionFactory [SPR-13732] #18305 Background initialization option for JPA EntityManagerFactory / Hibernate SessionFactory
- Add a functional way to register a bean [SPR-14832] #19398 Add a functional way to register a bean
80 votes, 77 watchers