Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

1. What are the appropriate risk weights for each category?

Answered: 1 week ago