1. Given the following code: public class Test ( static String message; private static class Worker...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Given the following code: public class Test ( static String message; private static class Worker extends Thread { public void run() ( try ( sleep (1000); } catch (InterruptedException e) {} message "I work."; public static void main(String args[]) throws InterruptedException { (new Worker()).start(); message = "I do not work."; Thread.sleep(2000); System.out.println(message); } a) [3 pts] The above program should print out "I work." Is it guaranteed to always do this? If not, why not? b) [3 pts] Would it help to change the parameters of the two invocations of Sleep? c) [4 pts] How would you guarantee that all changes to message will be visible to the main thread? 1. Given the following code: public class Test ( static String message; private static class Worker extends Thread { public void run() ( try ( sleep (1000); } catch (InterruptedException e) {} message "I work."; public static void main(String args[]) throws InterruptedException { (new Worker()).start(); message = "I do not work."; Thread.sleep(2000); System.out.println(message); } a) [3 pts] The above program should print out "I work." Is it guaranteed to always do this? If not, why not? b) [3 pts] Would it help to change the parameters of the two invocations of Sleep? c) [4 pts] How would you guarantee that all changes to message will be visible to the main thread?
Expert Answer:
Answer rating: 100% (QA)
a The above program may not always print out I work This is because the message variable is shared between the two threads and there is no synchroniza... View the full answer
Related Book For
Introduction To Java Programming And Data Structures Comprehensive Version
ISBN: 9780136520238
12th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these computer network questions
-
b. Prepare the adjusting entry to record bad debts expense using the estimate from part a. Assume the unadjusted balance in the Allowance for Doubtful Accounts is a $14,000 credit. c. Prepare the...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Give the decoding key for the encoding keys in Problems 2536. Minus 4, divide by 2.
-
LeBron's Bookstores has two divisions: books and electronics. The electronics division had another great year in 2012 with sales of $10 million, cost of goods sold of $6 million, operating expenses...
-
Elizabeth Flanigan and Associates is an engineering and design firm that specializes in developing plans for recycling plants for municipalities. The firm uses a job costing system to accumulate the...
-
Another name for the impersonal ledger is: a. Payables ledger b. General ledger c. Receivables ledger d. Cash ledger
-
Thoni Manufacturing has gathered information from materials requisition sheets and labor time sheets for several jobs worked on during the last month and needs to calculate the job costs. Required a....
-
Calculate the weighted mean for a distance, which was observed 5 times as 256.82, 256.79, 256.94, 256.81, 256.78 ft. The observations were given a weight of 3, 1, 1, 3, and 2, respectively. 256.82 ft...
-
Embutidos Vallina SA has two direct-cost categories: direct materials and direct manufacturing labour. Its single indirect-cost category (manufacturing overhead) is allocated on the basis of...
-
Burford Plastics manufactures plastic milk cartons. In the manufacturing process, all materials are added at the start of work-in-process and conversion costs are incurre uniformly through the...
-
How do post-translational modifications, such as phosphorylation, glycosylation, or ubiquitination, affect enzyme function and regulation ?
-
Mr. Seiki Yukimoto leads a virtual team that is composed of 15 professionals. The team connected primarily via videoconference, group decision-support software, email, text, and telephone. The team...
-
Discuss the role of social identity theory in shaping workplace dynamics. How might these dynamics contribute to intergroup conflict or cohesion within an organization ?
-
In financial analysis of the financial performance, there a number of ratios can be used to evaluate the performance of the company. Provide the following ratios with their definitions formulas and...
-
Describe how enzyme kinetics are analyzed using Michaelis-Menten theory, and discuss the implications of Vmax and Km in understanding enzyme efficiency and substrate affinity .
-
You work as a Human Resources manager supporting the insurance sales segment. At the beginning of the year his working group is analyzing the results obtained the previous year. Sales were below...
-
The cost curve for the city water supply is C(Q) = 16 + 1/4 Q2, where Q is the amount of water supplied and C(Q) is the cost of providing Q acre-feet of water. (An acre-foot is the amount of water...
-
Write the bin2Dec(String binaryString) method to convert a binary string into a decimal number. Implement the bin- 2Dec method to throw a NumberFormatException if the string is not a binary string....
-
Listing 28.14, NineTail.java, presents a solution for the nine tails problem. Revise this program for the 4 * 4 16 tails problem. Note it is possible that a solution may not exist for a starting...
-
Rewrite Listing 38.11 to handle a large factorial. Use the BigInteger class introduced in 14.12. Data from Listing 38.11 package chapter38: 2 3 1mport java.text.: 4 5 publ 1c class NewFactorialBean {...
-
A company often test-markets a proposed product in a specific area or location. Suppose that you wish to test-market your new, revolutionary SuperWax car wax, which requires only one application for...
-
The idea for New Belgium Brewing Company began with a bicycling trip through Belgium, where some of the worlds finest ales have been brewed for centuries. As Jeff Lebesch, a U.S. electrical engineer,...
-
It is helpful to think of a total product offering as having a combination of three interdependent elements: the core product itself, its supplemental features, and its symbolic or experiential...
Study smarter with the SolutionInn App