Java Executors newSingleThreadExecutor() Method

The newSingleThreadExecutor() method of Executors class creates an Executor that uses a single worker thread operating off an unbounded queue. (Note however that if this single thread terminates due to a failure during execution before the shutdown, a new one will take its place if needed to execute subsequent tasks.).

Syntax

Parameter

threadFactory - the factory to use when creating new threads

Returns

the newly created single-threaded Executor

Throws

NullPointerException

Example 1

Test it Now

Output:

current thread : main
 Executor Service...
Runnable...
Submit the task 
:: pool-1-thread-1

Example 1

Test it Now

Output:

Shutingdown executor
Running Task!
Next TopicJava Executors




Latest Courses