Javatpoint Logo
Javatpoint Logo

Java Executors newScheduledThreadPool() Method

The newScheduledThreadPool() method of Executors class creates a thread pool that can schedule commands to run after a given delay or to execute periodically.

Syntax

Parameter

corePoolSize - the number of threads to keep in the pool, even if they are idle

threadFactory - the factory to use when the executor creates a new thread

Returns

a newly created scheduled thread pool

Throw

NullPointerException

IllegalArgumentException

Example 1

Test it Now

Output:

class java.util.concurrent.ScheduledThreadPoolExecutor
size of mypool: 0
Thread Name: pool-2-thread-1
after sleep Thread Name: pool-2-thread-1

Example 2

Test it Now

Output:

class java.util.concurrent.ScheduledThreadPoolExecutor
size of mypool: 0
false
class java.util.concurrent.ScheduledThreadPoolExecutor
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