1

We are contemplating what would be the best way to gracefully shutdown our spring boot application.

We are using boot's shutdown endpoint and a shutdown hook to get notified on a shutdown.

The application is very heavily multi-threaded. It is constructed of multiple manager-like classes. Some of this classes holds executor services and/or kafka consumers. It is very important that jobs will not get lost.

We would like to build an easy infrastructure, so that each manager-like class would implement a "close" method that would be called when the shutdown endpoint is called. Of course we would like to minimize repetitions. It is also should be tested without boot (so we should be able to call the close method independently).

So far we were thinking of defining an interface with the "close" method that each of these classes will implement. We would rather not use an abstract class to not limit inheritance for other uses.

Registering for the shutdown event is where we are stuck. Should we use reflection with an annotation? Then we have to remember implementing the interface, and also adding the annotation for each class. Also - is it efficient?

dor.elmaliach
  • 515
  • 5
  • 14

0 Answers0