Performance: Bean lifecycle overview
MEDIUM IMPACT
This affects application startup time and memory usage by controlling how and when beans are created and initialized.
@Component
@Lazy
public class HeavyService {
public HeavyService() {
// heavy initialization logic
}
}
// Bean created only when first requested@Component
public class HeavyService {
public HeavyService() {
// heavy initialization logic
}
}
// All beans eagerly created by default| Pattern | Bean Creation Timing | Startup Impact | Memory Usage | Verdict |
|---|---|---|---|---|
| Eager Initialization | All beans at startup | High startup delay | Higher initial memory | [X] Bad |
| Lazy Initialization | On first use | Lower startup delay | Memory spread over time | [OK] Good |