Types of thread pools in java

What are the types of thread pools in java. I need to implement a robust multi-threaded application that uses heavy computing, which thread pool should I use?

+8
java multithreading threadpool
source share
5 answers

There are various thread pools in java:

  • Single Thread Artist: a pool of threads with only one thread. Thus, all assigned tasks will be performed sequentially. Method: Executors.newSingleThreadExecutor()

  • Cached thread pool: A thread pool that creates so many threads that it needs to complete a task in parrallel. Old available threads will be reused for new tasks. If a thread is not used for 60 seconds, it will be terminated and removed from the pool. Method: Executors.newCachedThreadPool()

  • Fixed thread pool: A thread pool with a fixed number of threads. If the thread is not available for the task, the task is queued, waiting for the end of another task. Method: Executors.newFixedThreadPool()

  • Scheduled thread pool: A thread pool for planning a future task. Method: Executors.newScheduledThreadPool()

  • Single Thread Scheduled Pool: a thread pool with a single thread for scheduling a future task. Method: Executors.newSingleThreadScheduledExecutor()

+15
source share

There are many types;)

There is, for example, ExecutorService . This is a "basic" implementation that allows you to submit tasks, etc. You probably want to use Executors to get a new one, since it has static factory methods for the most common scenarios.

With Java 7, you also have ForkJoinPool .

Also check out FutureTask , as it is a very convenient class for creating separate threads.

+4
source share

See Executors .

Each generic ExecutorService explained, and you are likely to find one that suits your needs.

+3
source share

You can read more about ThreadPoolExecutors here: http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html

However, it would be nice to take a look at the ForkJoinTask API: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinTask.html

+3
source share

It shows good animations in different concurrency constructs, maybe this will help you choose

http://sourceforge.net/projects/javaconcurrenta/

+3
source share

All Articles