user3773673
user3773673

Reputation: 25

Variable Amount of Threads/ redeclaring ExcutorService

Suppose I want to run 10 threads at a time, I would accomplish that by doing something along the lines of:

ExecutorService pool = Executors.newFixedThreadPool(10);

Is it possible to change the amount of threads to 15 using ExecutorService? So the default will be 10, but can I redeclare it to be a fixedthreadpool of 15?

Thanks!

Upvotes: 0

Views: 81

Answers (1)

jtahlborn
jtahlborn

Reputation: 53694

Assuming you mean "at runtime", you can cast the pool to ThreadPoolExecutor and call setMaximumPoolSize and setCorePoolSize.

Upvotes: 1

Related Questions