Performance: @PostConstruct and @PreDestroy
MEDIUM IMPACT
These annotations affect the initialization and cleanup phases of Spring beans, impacting application startup and shutdown time.
@PostConstruct
public void init() {
// lightweight setup only
this.cache = new HashMap<>();
// defer heavy tasks to async methods
asyncService.loadDataAsync();
}@PostConstruct
public void init() throws InterruptedException {
// heavy logic like blocking IO or long loops
Thread.sleep(5000);
}| Pattern | Blocking Operations | Startup Delay | Shutdown Delay | Verdict |
|---|---|---|---|---|
| Heavy blocking logic in @PostConstruct/@PreDestroy | Yes | High (seconds) | High (seconds) | [X] Bad |
| Lightweight logic with async offloading | No | Low (milliseconds) | Low (milliseconds) | [OK] Good |