Print numbers in sequence using 3 Threads & Executor Service

By | May 30, 2020

In this post, we will learn  How to write a java program to Print numbers in sequence using 3 Threads & Executor Service

NumbersGenerator.java is used by all three threads to generate numbers in Sequence

Each thread call method numbersGenerator.printNumbers(result) to generate numbers in sequence

Client program SequenceNumberGeneratorTest.java which using Executor framework 

If you run client program SequenceNumberGeneratorTest.java then this will generate below output:

pool-1-thread-1 1
pool-1-thread-2 2
pool-1-thread-3 3
pool-1-thread-1 4
pool-1-thread-2 5
pool-1-thread-3 6
pool-1-thread-1 7
pool-1-thread-2 8
pool-1-thread-3 9
pool-1-thread-1 10
pool-1-thread-2 11
pool-1-thread-3 12
pool-1-thread-1 13
pool-1-thread-2 14
pool-1-thread-3 15
pool-1-thread-1 16
pool-1-thread-2 17
pool-1-thread-3 18
pool-1-thread-1 19
pool-1-thread-2 20

You May Also Like:

Java Program to Swap two numbers using Bitwise XOR Operator?
How to reverse a number in Java
How to check Armstrong number java program
Java program to find factorial of a number
Java Program to Calculate the Power of a Number
Check whether a number is prime or not

That’s all about Java Program to Print numbers in sequence using 3 Threads & Executor Service
If you have any feedback or suggestion please feel free to drop in below comment box. 

Leave a Reply

Your email address will not be published.