You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we use @PreDestroyto handle application shutdowns which is not optimal because @PreDestroy can also be called when the bean is destroyed manually.
Solution
Use ApplicationListener<ContextClosedEvent> for such cases.
@Component
public class AppShutdownListener implements ApplicationListener<ContextClosedEvent> {
@Override
public void onApplicationEvent(ContextClosedEvent event) {
System.out.println("Application is shutting down. Cleaning up resources...");
}
}
Use the existing ShutdownSupport for this.
Change predestroy() to onShutdown()
The text was updated successfully, but these errors were encountered:
Situtaiton
Currently we use
@PreDestroy
to handle application shutdowns which is not optimal because@PreDestroy
can also be called when the bean is destroyed manually.Solution
Use
ApplicationListener<ContextClosedEvent>
for such cases.Use the existing
ShutdownSupport
for this.Change
predestroy()
toonShutdown()
The text was updated successfully, but these errors were encountered: