Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-8767

Parallel bean initialization during startup

    Details

    • Type: New Feature
    • Status: Reopened
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.1 RC1
    • Fix Version/s: 5.x Backlog
    • Component/s: Core

      Description

      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:

      1. Find all bean definitions that don't have any unresolved dependencies.
      2. Schedule creation of each bean found in 1. in a separate concurrent task to allow parallel creation
      3. 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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                nurkiewicz Tomasz Nurkiewicz
                Last updater:
                Filip Panovski
              • Votes:
                72 Vote for this issue
                Watchers:
                70 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Days since last comment:
                  9 weeks, 6 days ago