Simultaneous tasks execution using RxJava2
Using RxJava2 library I prepared ITask implementation (class: ConcurrentTasksExecutor
) which takes given tasks (implementations of ITask) and executes them simultaneously using multiple threads.
Number of threads is mandatory parameter defined in constructor and must be higher than zero.
- Spring Boot
- RxJava 2
- Lombok
- Google Guava
Extract project in some location on your local machine.
Go to the project location:
cd /path/to/project/location
Build project with maven by executing command:
./mvnw clean install
Execute .jar file:
java -jar target/rxjava2-simultaneous-tasks-0.0.1-SNAPSHOT.jar
By default application should be accessible under localhost:8080. There are only two endpoints described in next sections.
You can use API method to check how long will it take to execute couple of tasks simultaneously.
Assume that we want to test how long will take to execute 3 tasks using 2 threads.
Threads: 2
Tasks:
- Task1 - we define that this task should finished after 3 seconds
- Task2 - we define that this task should finished after 2 seconds
- Task3 - we define that this task should finished after 2 seconds
API call: GET http://localhost:8080/tasks/concurrent?task=3&task=2&task=2&threads=2
Test the same example by executing tasks in one thread.
API call: GET http://localhost:8080/tasks/sequential?task=3&task=2&task=2