Reputation: 57
Say you have a ScheduledExecutorService
that is initialized in the main thread of the application and we add scheduled jobs to this service. If the main thread finishes, will the ScheduledExecutorService
automatically cease creating new threads?
Upvotes: 1
Views: 721
Reputation: 4190
It depends on whether the underlying thread of the Executor is a daemon thread.
In the default configuration it is not the case. This means that the executor won't stop when the end of main is reached. This also means that the Executor could still create new threads.
However, if the executor uses daemon threads the application will terminate if there are no other non-daemon threads.
Upvotes: 2