Performance: @Scope for bean scope
MEDIUM IMPACT
This affects application startup time and memory usage by controlling bean lifecycle and instantiation frequency.
@Component @Scope("prototype") public class MyService { // new instance created on each injection }
@Component public class MyService { // default singleton scope } // Injected everywhere, always created once and shared
| Pattern | Bean Instantiation | Memory Usage | Thread Safety | Verdict |
|---|---|---|---|---|
| Singleton scope for stateful beans | 1 instance at startup | High if stateful | Low, shared instance | [X] Bad |
| Prototype scope for stateful beans | New instance per injection | Moderate | High, isolated instances | [OK] Good |
| Request scope for web beans | New instance per HTTP request | Moderate | High, per request isolation | [OK] Good |
| Lazy singleton for heavy beans | Instance created on first use | Low at startup | High | [OK] Good |