Java program to Print numbers in sequence using 2 Threads & Executor Framework

By | May 30, 2020

OddAndEvenNumberGenerator.java is used by both the threads to print odd and even numbers

OddNumberPrinter.java calls printOddNumber() method to print odd numbers

EvenNumberPrinter.java calls printEvenNumber() method to print even numbers

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-1: 3
pool-1-thread-2: 4
pool-1-thread-1: 5
pool-1-thread-2: 6
pool-1-thread-1: 7
pool-1-thread-2: 8
pool-1-thread-1: 9
pool-1-thread-2: 10
pool-1-thread-1: 11
pool-1-thread-2: 12
pool-1-thread-1: 13
pool-1-thread-2: 14
pool-1-thread-1: 15
pool-1-thread-2: 16
pool-1-thread-1: 17
pool-1-thread-2: 18
pool-1-thread-1: 19
pool-1-thread-2: 20

You May Also Like:

What are the standard ways for handling TimeZone in database transactions?
How to convert time from One Time Zone to another in Java?
What will be the output of this date/time program?
What is the difference Between java.util.Date and java.sql.Date in Java ?

That’s all about Java program to Print numbers in sequence using 2 Threads & Executor Framework
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 *