Everyone
Everyone

Reputation: 2376

Usage of Executors.newSingleThreadScheduledExecutor

The javadoc for

Executors.newSingleThreadScheduledExecutor 

says "... the returned executor is guaranteed not to be reconfigurable to use additional threads".

What does the above sentence mean? Does it mean the returned instance may not have nested threads?

Upvotes: 3

Views: 2739

Answers (3)

Maurice Perry
Maurice Perry

Reputation: 32831

I guess it means that only one thread is processing the tasks, and there is no way to add more threads after the creation

Upvotes: 2

Jens Schauder
Jens Schauder

Reputation: 81930

It means, that if you share the Executor, without worying that some piece of code reconfigures the Executor to use 23 Threads and thereby killing your machine.

Upvotes: 2

Gerco Dries
Gerco Dries

Reputation: 6712

It means that you cannot add additional threads to this executor after it has been created. It is guaranteed to have only one thread.

This is useful when want to ensure that only a single background task is active at any given time in your application. Mostly useful when you will be providing a reference to this executor to potentially untrusted code (code written by someone other than you).

Upvotes: 5

Related Questions