I have SpringBoot application which is load some configuration and runs a longtime processing in method annotated with @PostConstract. There are some resources which should be released if application completed successfully or with an Error.
The question is how to make the most correct release of application resources? Is that enough to make it in @PreDestroy annotated method or I should also catch the exception in @PostConstract annotated method.
@SpringBootApplication
@Import(MyConfiguration.class)
public class MySpringApplication {
@Autowire
ProcessRunner processRunner;
@Autowire
ResourceBean resourceBean;
public static void main(String[] args) {
SpringApplication.run(MySpringApplication.class, args);
}
@PostConstruct
void postConstruct {
try {
processRunner.run()
} catch (Exception ex) {
// Do we really need this Exception handling to release resource?
resourceBean.release();
}
}
@PreDestroy
void preDestroy() {
resourceBean.release();
}
}