Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java, code the following program so that two people working at a desk each take their time to file their own paper ( output
In java, code the following program so that two people working at a desk each take their time to file their own paper ( output below.)
Overvievw Following the discussion of threads in the lecture, this lab will give students the opportunity to implement them and note their behaviors. Two office associates are attempting to complete their daily task of filing stacks of papers. Your job is to instruct them on who is to work at any given time. Throughout this lab you will try having them work at ther own pace, yielding to each other, sleeping, and sharing a single desk. Note: When sharing a single desk, only one person can file at a time, so make it fair by letting them alternate between who gets to use it. Tasks Create a text document to keep notes for this assignment. This must be submitted along with the two java files for credit. Create a new Java Project. Create the following two classes in the project: 1. 2. 3. a. MyThreadMain.java will contain your main method. b. MyThread.java will be your thread class. This class must inherit from the Thread class. i. Declaration: public class MyThread extends Thread Since MyThread is a subclass of the Thread superclass, it inherits all of its attributes and methods. In this class, we will want to override the run method that exists in the Thread class. This can be done by simply creating a new run method. All code that you want the thread to execute should start from this method. 4. In order to start a thread, you will create and execute the thread by calling its start method from the MyThreadMain class. The start method calls run on its own. a. Example: Assuming you had a thread named Thread1, you would call it as: Thread1.start()
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