Skip to content

io microsphere spring context event ParallelPreInstantiationSingletonsBeanFactoryListener

github-actions[bot] edited this page Jun 18, 2026 · 18 revisions

ParallelPreInstantiationSingletonsBeanFactoryListener

Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.context.event | Since: 1.0.0

Source: microsphere-spring-context/src/main/java/io/microsphere/spring/context/event/ParallelPreInstantiationSingletonsBeanFactoryListener.java

Overview

A BeanFactoryListener implementation that pre-instantiates singleton beans in parallel to improve application startup performance. This class leverages multi-threading to initialize beans concurrently while respecting bean dependencies.

Configuration Properties

`#THREADS_PROPERTY_NAME`

    The number of threads to use for parallel pre-instantiation. Default is based on the number of
    available processors, with a minimum of 1 thread.


`#THREAD_NAME_PREFIX_PROPERTY_NAME`

    The prefix for the thread names used during parallel pre-instantiation. Default is:
    `#DEFAULT_THREAD_NAME_PREFIX`

Example Usage

`# application.properties
microsphere.spring.pre-instantiation.singletons.threads=4
microsphere.spring.pre-instantiation.singletons.thread.name-prefix=MyCustomThread-
`

Example Usage

This listener is typically registered in a Spring configuration class as follows:

{@code

### Declaration

```java
public class ParallelPreInstantiationSingletonsBeanFactoryListener implements BeanFactoryListenerAdapter,
```

**Author:** Mercy

## Version Information

- **Introduced in:** `1.0.0`
- **Current Project Version:** `0.2.27-SNAPSHOT`

## Version Compatibility

This component is tested and compatible with the following Java versions:

| Java Version | Status |
|:---:|:---:|
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |

## Examples

### Example 1

```java
# application.properties
microsphere.spring.pre-instantiation.singletons.threads=4
microsphere.spring.pre-instantiation.singletons.thread.name-prefix=MyCustomThread-
```

### Example 2

```java
@Configuration
public class AppConfig {
    @Bean
    public BeanFactoryListener parallelPreInstantiationListener() {
        return new ParallelPreInstantiationSingletonsBeanFactoryListener();
    }
}
```

## Usage

### Maven Dependency

Add the following dependency to your `pom.xml`:

```xml

    io.github.microsphere-projects
    microsphere-spring-context
    ${microsphere-spring.version}

```

> **Tip:** Use the BOM (`microsphere-spring-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-spring#getting-started) guide.

### Import

```java
import io.microsphere.spring.context.event.ParallelPreInstantiationSingletonsBeanFactoryListener;
```

## API Reference

### Public Methods

| Method | Description |
|--------|-------------|
| `onBeanFactoryConfigurationFrozen` |  |
| `setEnvironment` |  |
| `setBeanFactory` |  |

## See Also

- `EventPublishingBeanInitializer`
- `EventPublishingBeanBeforeProcessor`
- `EventPublishingBeanAfterProcessor`
- `BeanFactoryListeners`
- `BeanFactoryListener`
- `BeanFactoryListenerAdapter`
- `ConfigurableListableBeanFactory`
- `DefaultListableBeanFactory`

---

*This documentation was auto-generated from the source code of [microsphere-spring](https://github.com/microsphere-projects/microsphere-spring).*

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally