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

Part 3 Nursing Assignment Help

To begin, work through the reference list that was created in the “Section B: Problem Description” assignment in Topic 2. Appraise each resource using the “Rapid Critical Appraisal Checklists,” available in the textbook appendix. The specific checklist you use will be determined by the type of evidence within the resource.

Social research and journalism have much in common. Briefly, what

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.

Answer ONE (1) of the following questions in your post:

Answer ONE (1) of the following questions in your post: (3-4 paragraph posts, attention to grammar, critical analysis rather than recitation of materials) apply to your main post Question #1: The authors find that parliaments have different “modes” of lawmaking across differing European countries. How do these differ from one

Each student is required to read two journal articles on

  Each student is required to read two journal articles on issues addressing acquisitions. For your first paper, the articles needs to address “Earned Value Management” in the acquisitions field. The journals must be research oriented, such as those found in the APUS library. The articles must be cited and

Lyme Disease Identified With GIS Report Nursing Assignment Help

Write a brief report on lime disease identification using geographical information system. Expert Solution Preview Lyme disease is a tick-borne illness caused by the bacterium Borrelia burgdorferi and is transmitted to humans through the bite of infected black-legged ticks. Early identification and prompt treatment are crucial in managing the disease

Assignment 8.1: Nursing Theory in Practice

Topic: Improvement of Discharge Patient Teaching. Review the literature regarding the Topic. Review one grand theory, one mid-range theory, and one shared/borrowed theory that could be used to frame a solution or create a research study that addresses your practice issue. Write a brief (500 – 750 word) summary of

Environmental Justice (Shrimp Cultivation in Bangladesh)

Strategy Paper: For this option, students will develop a document that offers guidance, advice, and direction to an organization (educational, non-profit, private, or government agency) that will advance their goals. The paper will offer new ideas, tactics, and directions that you believe will increase the organization’s impact and improve outcomes

Family disaster plan

You will formulate a disaster readiness plan for your selected community family. Discuss your selected plan. Provide your community family with disaster planning information and the disaster planning guide below. Practice the plan once and be sure to leave them a copy. If the family has a plan review it

NO Plagiarism Please read and follow all directions Based on

NO Plagiarism Please read and follow all directions  Based on companies Guess and SuperDry COMPARISON SHOULD INCLUDE: 1. -STRATEGY PURSUED BY THE TWO RETAILERS, EACH COMPANY ‘S TARGET MARKET AND GENERAL APPROACH TO SATISFYING THE NEEDS OF THAT TARGET. 2.-THE RETAIL MIXES (STORE LOCATION, MDSE, PRICING, ADVERTISING AND PROMOTION, LOCATION

Implementing a performance management system

Description Understanding the steps to take before implementing a performance management can greatly improve organizational success. Consider how you would implement a performance management system for your organization; include details about the communications plan, the appeals process, training programs for raters, and the pilot test for your performance management system.

he video discusses the emergence of e-commerce growth due to

  he video discusses the emergence of e-commerce growth due to the pandemic. Shopify’s COO at the time discusses the growth of online shopping and the need for companies of all industries to have a website and online marketing presence to compete. After watching, answer the following question: 1) What

The Power of Persuasion Assignment 1: Laying the Foundations for

The Power of PersuasionAssignment 1: Laying the Foundations for Making a CaseDue: Week 3Points: 150 Skill(s) Being Assessed: Problem Solving (Information Literacy) Criteria for Success: In this assignment, you will: Define a topic for a persuasive proposal, and explain the importance of the topic to you within the context of

Principals must be instructional and ethical leaders. What does this

Principals must be instructional and ethical leaders. What does this mean in terms of personal integrity, fairness, and ethics? What does this statement mean to you as it relates to all aspects of your school? Can a principal be an instructional leader and also be ethically challenged? Why or why

Complete Case Project 10-3 from page 466 Case Project 10-3:

 Complete Case Project 10-3 from page 466  Case Project 10-3: Rooting and Jailbreaking Research rooting and jailbreaking. What are the advantages? What are the disadvantages? How frequently is this technology used? Can a device that has been broken return to its default state? If so, how? Finally create a list

1. I love that you have the budget planned out

1.  I love that you have the budget planned out for not only the short term effects but the long term sustainability. Will there be some upkeep of these virtual reality simulators?  Will there be a specific role that is responsible for the upkeep of the simulation scenarios and coinciding