Given @Scheduled
, I'm going to assume your ApplicationContext
has some scheduled configuration. This means that your are creating (implicitly or explicitly) a SchedulerExecutorService
which spawns non-daemon threads. The application will not end until all non-daemon threads have completed. One of these threads is executing your periodic
method every 5000 milliseconds.
Now, you could put your ApplicationContext
instantiation in a try-with-resources
. Once execution leaves the try
block, the ApplicationContext
would be closed, shutting down the ScheduledExecutorService
and eventually terminating your program.