Schrodinger's_hat
Schrodinger's_hat

Reputation: 57

Does a ScheduledExecutorService stops creating new threads when the class's main thread finishes?

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

Answers (1)

Jimmy T.
Jimmy T.

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

Related Questions