SingleThreadExecutor and ThreadFactory

Developer87

Am I right that every time, when we performing several submit operations:

ExecutorService executor = Executors.newSingleThreadExecutor(
            new MyThreadFactory("someExecutor"));
executor.submit(...);
executor.submit(...);
executor.submit(...);

Method java.util.concurrent.ThreadFactory#newThread executes only once? Or it executes every time and creates a new thread per submit call?

Jean Logeart

It reuses the same thread everytime.

That is the beauty of thread pools: avoid the cost of creating a new thread by reducing the per-task invocation overhead.

You can read more about how threads are actually created in the ThreadPoolExecutor documentation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

SingleThreadExecutor VS plain thread

Java ThreadFactory with Queue

Is it necessary to use AtomicInteger in a ThreadFactory?

ThreadFactory usage in Java

Problem with Java ThreadFactory

Callable thread for singleThreadExecutor is working as synchronously

Spring 3 setting ThreadFactory for ThreadPoolTaskExecutor

Difference between a SingleThreadExecutor and a Handler in Android (by Example)

How to pause/restart SingleThreadExecutor (ExecutorService) in Java?

How to use lambda to initialize ThreadFactory with named Thread

Java: How does ThreadFactory handles Threads?

Does java `SingleThreadExecutor` guarantee previous work is finished before new one starts?

Why does 11010100 << 1 equal 110101000, not 10101000?

Odd Java ternary behavior when assigning value. What is Java doing behind the scenes for this to happen?

Java 8 - How to get single values out of Map of Lists?

How to solve x - a tan(x) = 0 with Sympy

Spring @Transactional is consistantly rolling back transaction upon exception

Basic mySQL - Don't know how to show all results including 0

How can I refresh a page with jQuery?

C++ and Java array declaration/definition : differences

Spring security switch to Ldap authentication and database authorities

Multi language database, with default fallback

How to detect string which contains only spaces?

Change value in a 2-value column to its opposite only if a condition in another column is met

Protocol Buffer Error version

Move constructor C++11

qml virtual keyboard: keyboardDesignWidth and Height

Create a bot for a closed facebook group

align items vertically in rowlayout