Javatpoint Logo
Javatpoint Logo

Java Executors newFixedThreadPool() Method

The newFixedThreadPool() method of Executors class creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most n Threads will be active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available.

Syntax

Parameter

nThreads - the number of threads in the pool

threadFactory - the factory to use when creating new threads

Returns

Throws

IllegalArgumentException

NullPointerException

Example 1

Test it Now

Output:

size of mypool: 0
Thread Name: pool-1-thread-1
after sleep Thread Name: pool-1-thread-1

Example 2

Test it Now

Output:

size of mypool: 0
Thread Name: pool-1-thread-1
after sleep Thread Name: pool-1-thread-1
Next TopicJava Executors





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA