Java program to Print numbers in sequence using 3 Threads

By | May 29, 2020

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

Numbers have to print in below order by all 3 Threads::

Thread-1   Thread-2   Thread-3
1                    2                        3
4                   5                         6
7                  8                          9
10               11                         12

————————————–

 

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

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

Thread-1 1
Thread-2 2
Thread-3 3
Thread-1 4
Thread-2 5
Thread-3 6
Thread-1 7
Thread-2 8
Thread-3 9
Thread-1 10

You May Also Like:

How to convert number to words in java
How to swap two numbers with or without temporary variable in java
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?
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. Required fields are marked *