Question
In Java: Consider a shared counter whose values are non-negative integers, initially zero. A time-printing thread increments the counter by one and prints its value
In Java:
Consider a shared counter whose values are non-negative integers, initially zero. A time-printing thread increments the counter by one and prints its value each second from the start of execution. A message-printing thread prints a message every fifteen seconds. Have the message-printing thread be notified by the time-printing thread as each second passes by. Add another message-printing thread that prints a different message every seven seconds. Such addition must be done without modifying the time-printing thread implementation.
Have all involved threads share the counter object that is updated by the time-printing thread every second. The time-printing thread will notify other threads to read the counter object each time it updates the counter, then each message-printing thread will read the counter value and see if its assigned time period has elapsed; if so, it will print its message.
Write a Main2 class that contains the main method that tests your implementation. The output should look as follows:
1 2 3 4 5 6
7 second message
7 8 9 10 11 12 13
7 second message
14
15 second message
15 16 17 18 19 20
7 second message
21 22 23 24 . . .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started