Javatpoint Logo
Javatpoint Logo

Java ThreadPoolExecutor preStartAllCoreThreads() Method

The preStartAllCoreThreads() method of ThreadPoolExecutor class starts all the core threads, causing them to wait for the work idly. This overrides the default policy of starting core threads only when new tasks are executed.

Syntax

Parameters

NA

Return

The number of threads started

Throw

Does not throw the exception.

Example 1

Test it Now

Output:

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

Example 2

Test it Now

Output:

Starting threads
Threads started, main ends
Thread sleeping for 1000 i=0
Thread sleeping for 1000 i=1
Thread sleeping for 1000 i=2
Thread sleeping for 1000 i=3
Thread sleeping for 1000 i=4
 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