I wonder what is the best way to shutdown a ScheduledExecutorService. In the following code I start a Runnable every second and I want to stop scheduling new tasks after 10 seconds. And I want the app to close nicely and not hang because the service is not shutdown.
So I shutdown() the service from another scheduled task from the same service.
It seems cumbersome to put the shutdown in the scheduled task from the same very service, that is why I am asking whether there are more appropriate ways to do it.