Spring ThreadPoolTaskExecutor with Callable interface for concurrency programming

Callable is a Java interface that is an useful methodology for control multi-threading returns on concurrency development.

The tutorial will guide you to build a concurrency program with ThreadPoolTaskExecutor of Spring Framework and Callable interface.

I. Technology

– Java 8
– Maven 3.3.9
– Editor: Spring Tool Suite – Version 3.7.3.RELEASE

II. Overview of Spring multi-thread with Callable project

– Program has 5 threads, that works concurrently. At parent thread, for managing the returns of all child threads, We use Callable interface.

1. Structure of project

spring thread pool callable structure

2. Step to do

– Create Spring Boot project.
– Setup ThreadPoolTaskExecutor.
– Create CallableWorker that implements Callable interface.
– Create a Simple Web Controller

III. Practice
1. Create Spring Boot project

Open Spring Tool Suite, choose File->New->Spring Starter Project, input project information as below picture:

Press Next button, then add needed dependencies:
– For Web MVC dependency, choose Web then select Web as below:


Press Finish then Spring Boot Project will be created.

Check pom.xml dependency:

2. Setup ThreadPoolTaskExecutor

– Configure application.properties:

– Configure a Spring ThreadPool:

3. Create Callable Worker

4. Create a Simple Web Controller

IV. Run Project

– Build Spring Boot project
Set Goals: clean install

– Run Project:

– Logs

V. Source Code


By grokonez | October 30, 2016.

Last updated on June 4, 2017.

Related Posts

1 thought on “Spring ThreadPoolTaskExecutor with Callable interface for concurrency programming”

  1. In above example if I move private void process() to another Bean (ThreadPoolThreadtask) and I wanted to call this method from there, below implementation is giving me issue (Null Pointer exception) as bean is not getting initialized. Can you please help.

Got Something To Say:

Your email address will not be published. Required fields are marked *