Javatpoint Logo
Javatpoint Logo

Java ThreadPoolExecutor setCorePoolSize() Method

The setCorePoolSize() method of ThreadPoolExecutor class sets the core number of threads in the pool. This method accepts the size of the pool as a parameter.

Syntax

Parameters

corePoolSize - the new core size

Return

NA

Throw

IllegalArgumentException - if corePoolSize < 0 or corePoolSize is greater than the maximum pool size

Example 1

Test it Now

Output:

Core Pool size after execution: 5
Running Thread Name: pool-1-thread-1
Running Thread Name: pool-1-thread-2
Completed Thread Name: pool-1-thread-2
Completed Thread Name: pool-1-thread-1

Example 2

Test it Now

Output:

Starting threads
 After execute Core pool size : 5
Thread sleeping for 1000 i=0
Thread sleeping for 1000 i=0
Threads started, main ends

Thread sleeping for 1000 i=1
Thread sleeping for 1000 i=1
Thread sleeping for 1000 i=2
Thread sleeping for 1000 i=2
Thread sleeping for 1000 i=3
Thread sleeping for 1000 i=3
Thread sleeping for 1000 i=4
Thread sleeping for 1000 i=4
 now  i > 5 :
 now  i > 5 :






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