Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring ThreadPoolTaskExecutor vs Java Executorservice cachedthreadpool [closed]

What are the pros and cons of using

Spring ThreadPoolTaskExecutor vs Java Executorservice cachedthreadpool even though spring is wrapper of Java concurrency.

Just would like to know the flexibility in using them.

like image 231
BalaB Avatar asked Jul 23 '14 06:07

BalaB


2 Answers

One of the added Advantage of using ThreadPoolTaskExecutor of spring is that it is well suited for management and monitoring (e.g. through JMX), providing several useful attributes: "corePoolSize", "maxPoolSize", "keepAliveSeconds" (all supporting updates at runtime); "poolSize", "activeCount".

apart from that it is obviously simple to use if you already have spring injections implemented in your application. by using it you can directly inject thread pool by setter injection like below:

<bean id="taskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="5" />
    <property name="maxPoolSize" value="10" />
    <property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean> 

ThreadPoolTaskExecutor Doc

on the other hand ExecutorService CachedThreadPool is good utility to share your most recent under utilized threads ( Under 60 seconds ). It is important to point out that CachedThreadPool is not separate class its method ( newCachedThreadPool() ) .

CachedThreadPool Doc

like image 54
Pramod S. Nikam Avatar answered Oct 23 '22 20:10

Pramod S. Nikam


After Googling you will get the following:

Executorservice

The java.util.concurrent.ExecutorService interface represents an asynchronous execution mechanism which is capable of executing tasks in the background. An ExecutorService is thus very similar to a thread pool. In fact, the implementation of ExecutorService present in the java.util.concurrent package is a thread pool implementation.

ThreadPoolTaskExecutor

This implementation can only be used in a Java 5 environment but is also the most commonly used one in that environment. It exposes bean properties for configuring a java.util.concurrent.ThreadPoolExecutor and wraps it in a TaskExecutor. If you need something advanced such as a ScheduledThreadPoolExecutor, it is recommended that you use a ConcurrentTaskExecutor instead.

like image 40
mkazma Avatar answered Oct 23 '22 20:10

mkazma