Question
Java Language in Eclipse: Using the concepts from the Concurrency Basics Tutorial I provided in Modules, write a program that consists of two threads. The
Java Language in Eclipse:
Using the concepts from the Concurrency Basics Tutorial I provided in Modules, write a program that consists of two threads. The first is the main thread that every Java application has. The main thread should create a new thread from the Runnable object, MessageLoop, and wait for it to finish. If the MessageLoop thread takes too long to finish, the main thread should interrupt it. Use a constant to store the maximum number of seconds to wait. The main thread should output a message stating that it is still waiting every second (or a different value so that it will output this message a few times, depending on your other wait times).
The MessageLoop thread should print out a series of 5 messages. It should wait a few seconds between printing messages to create a delay. Make the value sufficiently high to cause main to output Continuing to wait messages. If it is interrupted before it has printed all its messages, the MessageLoop thread should print "Message loop interrupted" and exit.
Sample output :
main: Starting MessageLoop thread main: Waiting for MessageLoop thread to finish main: Continuing to wait... main: Interrupting Thread-0: Message loop interrupted main: Finished!
Sample output 2:
main: Starting MessageLoop thread main: Waiting for MessageLoop thread to finish main: Continuing to wait... main: Continuing to wait... Thread-0: Message 1 main: Continuing to wait... main: Continuing to wait... Thread-0: Message 2 main: Continuing to wait... main: Continuing to wait... Thread-0: Message 3 main: Continuing to wait... main: Continuing to wait... Thread-0: Message 4 main: Continuing to wait... main: Continuing to wait... Thread-0: Message 5 main: Finished!
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