1 Homework 4 1. (10 pts) For the following program, explain the interesting elements related to threads. Focus on explaining the output of the

1

Homework 4

1. (10 pts) For the following program, explain the interesting elements related to threads. Focus on
explaining the output of the program.

1 public class TaskThreadDemo {
2 public static void main (String args []) {
3 String [] sa = {“a”, “X”, “+”, “.”};
4 for (String s: sa) {
5 Runnable ps = new PrintChar (s, 200);
6 Thread ts = new Thread (ps, s);
7 ts.start ();
8 } // end for each character
9 } // end main
10 } // end class TaskThreadDemo
11
12 class PrintChar implements Runnable {
13 String ch;
14 int times;
15
16 public PrintChar (String c, int n) {
17 ch = c;
18 times = n;
19 } // end constructor
20
21 public void run () {
22 for (int i = 0; i < times; i++) {
23 System.out.print (ch);
24 } // end for loop
25 } // end method run
26 } // end class PrintChar

2. (10 pts) What is changed if the method called on line 7, start(), is replaced with run()? Explain (of
course). Focus on explaining the output of the program.

3. (10 pts) What is changed if the method Thread.yield() is added between lines 23 and 24? Explain.
Focus on explaining the output of the program.

4. (10 pts) Modify the above program so that the Thread.sleep method is called after each character has
been printed causing it to sleep for 500 milliseconds. Describe how that modification has altered the
output and explain why the change had the effect that you described.

5. (10 pts) Modify the above program so that the Thread.sleep method is called after each thread is
created in the main method causing it to sleep for 500 milliseconds. Describe how that modification has
altered the output and explain why the change had the effect that you described.

2

Grading Rubric:

Attribute Meets Does not meet
Problem 1 10 points

Explains the interesting elements
related to threads. Focuses on
explaining the output of the program.

0 points
Does not explain the interesting elements
related to threads. Does not focus on
explaining the output of the program.

Problem 2 10 points
Explains what is changed if the
method called on line 7, start(), is
replaced with run().Focuses on
explaining the output of the program.

0 points
Does not explain what is changed if the
method called on line 7, start(), is replaced
with run(). Does not focus on explaining
the output of the program.

Problem 3 10 points
Explains what is changed if the
method Thread.yield() is added
between lines 23 and 24. Focuses on
explaining the output of the program.

0 points
Does not explain what is changed if the
method Thread.yield() is added between
lines 23 and 24. Does not focus on
explaining the output of the program.

Problem 4 10 points
Explains how the output is changed if
the Thread.sleep method is called
after each character has been
printed.

0 points
Does not explain how the output is
changed if the Thread.sleep method is
called after each character has been
printed.

Problem 5 10 points
Explains how the output is changed if
the Thread.sleep method is called
after each thread is created in the
main method.

0 points
Does not explain how the output is
changed if the Thread.sleep method is
called after each thread is created in the
main method.

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

Week 15 DiscussionThis is a required assignment worth 15 points

 Week 15 DiscussionThis is a required assignment worth 15 points (15-points/1000-points). Assignment must be submitted by the due date. No late assignments are allowed. Please discuss the following topics and provide substantive comments to at least two other posts. Select from the following list four (4) topics and discuss. Use only

Using the change initiative you discussed in the previous discussion,

  Using the change initiative you discussed in the previous discussion, Stakeholder Analysis, or a similar change initiative, complete the force field analysis template in the Resources to include driving forces as well as restraining and resisting forces. Respond to the following: How can you disrupt the equilibrium to facilitate

For this assignment, you will use the six-step hypothesis testing

  For this assignment, you will use the six-step hypothesis testing process (noted below) to run and interpret a correlation analysis using SPSS. The following vignette will inform you of the context for this assignment. A data file is provided in the week’s resources for use in this assignment.  Also

PLEASE CHECK THE SCREENSHOTS! Fleur’s Flowers was started four years

PLEASE CHECK THE SCREENSHOTS! Fleur’s Flowers was started four years ago by siblings Matt and Sarah Harris. The idea was to create an online flower store that delivered fresh flowers and floral decorations nationally along with occasional ‘pop-up’ stores. In the new business, Sarah focused on supplier sourcing and plant

Comparison charts are graphic visual representations of information, knowledge, or

  Comparison charts are graphic visual representations of information, knowledge, or data to present information concisely and clearly. The intent of graphics is to assist the audience with understanding the data presented. Create a comparison chart identifying 3–5 development theories and how each theory impacts team development. Provide a written

In Module 3 Discussion 1, we will be discussing the

  In Module 3 Discussion 1, we will be discussing the Executive, Legislative, and Judicial branches of our government and explore their connection and role in the creation of the federal bureaucracy. To help you formulate an answer, be sure to review the Exploration for this module and Chapters 11, 12, 13

How do culture, gender, and interpersonal communication affect

                  In the wake of globalization, diversity has become a real issue in the workplaces. Most teams exhibit various aspects of diversity; often defined by social, racial, gender and culture elements. Therefore, the existence of such diverse social groups has prompted the modern organizations to come up

Suppose that you are asked to choose between Med-Arb and

Premium Paper Help is a professional writing service that provides original papers. Our products include academic papers of varying complexity and other personalized services, along with research materials for assistance purposes only. All the materials from our website should be used with proper references.

This is week 8, it is time to step back

This is week 8, it is time to step back and review the basic webpage created. Remember, this is just a starting point, if Wix is something you like, continue building your site. If you want to take what you learned to another platform, go for it, remember the lessons

Case Study: Introducing Scrum at P2P

This assignment is a case study. You will be presented with information concerning a company facing a situation that requires at least one decision to be made. Read the case and use the course material and your additional research to write a short paper that briefly identifies the issues and

Include a table of content. Choose any published database from

Include a table of content. Choose any published database from the internet * If the file is large, randomly choose 200 of the observations from the data. * Explain each variable in the file that you are analyzing. Be sure your file includes at least 3 scale variables and at least

Submit a draft of critical elements A through C of

 Submit a draft of critical elements A through C of Section I (Total Rewards Analysis) of the final project. Based on the case study analysis, discussion, and textbook reading up to this point in the course, you should have gathered enough information to analyze given aspects of a benefits and

The Chickenshit Club: Why the Justice Department Fails to Prosecute

1. Flashboys by Michael Lewis 2. The Chickenshit Club: Why the Justice Department Fails to Prosecute Executives by Jesse Eisinger 3. Skin in the Game: Hidden Asymmetries in Daily Life by Nassim Nicholas Taleb 4. Barbarians at the Gate: The Fall of RJR Nabisco by Bruan Burrough & John Helyar

Miami Dade College case study Nursing Assignment Help

Instructions: Use the Case Study Template to complete. Download Use the Case Study Template to complete. attached Be sure to include at least one reference. Include in-text citations as needed. Select one case to discuss. Case 1: A 42-year-old female complains of progressive weight gain of 20 pounds over the

– 1 page, APA format, in-text citation, references include (

– 1 page, APA format, in-text citation, references include ( minimum of 2) – Topic: You have been assigned as a global health consultant to discuss the SDOH, social cohesion component, as it is applied to one low/middle-income country.  1. Select one low/middle-income country. Provide a basic profile with information relevant