What is the output of the following application? A. A deadlock is produced at runtime. B. A
Question:
What is the output of the following application?
A. A deadlock is produced at runtime.
B. A livelock is produced at runtime.
C. 1000
D. The code does not compile.
E. The result is unknown until runtime because stroke is not written in a thread-safe manner and a write may be lost.
F. None of the above.
Transcribed Image Text:
package olympics; import java.util.concurrent.*; public class Athlete { int stroke = 0; public synchronized void swimming () { } private int getStroke() { synchronized(this) { return stroke; } stroke++; } public static void main(String... laps) { Executor Service s = Executors.newFixed ThreadPool (10); Athlete a new Athlete(); for (int i=0; i <1000; i++) { s.execute(() -> a.swimming()); } s.shutdown(); System.out.print(a.getStroke()); } }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
Based on the provided code snippet it looks like this is Java code that creates a thread pool and performs a synchronized increment operation on an in...View the full answer
Answered By
Muhammad adeel
I am a professional Process/Mechanical engineer having a vast 7 years experience in process industry as well as in academic studies as a instructor. Also equipped with Nebosh IGC and lead auditor (certified).
Having worked at top notch engineering firms, i possess abilities such as designing process equipment, maintaining data sheets, working on projects, technical biddings, designing PFD and PID's etc.
Having worked as an instructor in different engineering institutes and have been involved in different engineering resrearch projects such as refinery equipment designing, thermodynamics, fluid dynamics, chemistry, rotary equipment etc
I can assure a good job within your budget and time deadline
4.90+
52+ Reviews
60+ Question Solved
Related Book For
OCP Oracle Certified Professional Java SE 11 Developer Practice Tests Exam 1Z0 819 And Upgrade Exam 1Z0 817
ISBN: 9781119696131
1st Edition
Authors: Scott Selikoff, Jeanne Boyarsky
Question Posted:
Students also viewed these Computer science questions
-
As the pendulum swings from position B to position A, what is the relationship of kinetic energy to potential energy (neglect friction)? The kinetic energy increase is equal to the potential energy...
-
1. Journalize the account receivable and account payable transactions (transactions are described on the next page) in a general journal, post them to the general ledger (just the accounts receivable...
-
M Corp owns 100% of R Corp. R Corp owns 50% of G Corp, a Corp established in China M Corp owns the other 50% of G Corp Given the above, which of the Corps form a tax consolidated group under US...
-
You are the manager of a local coffee shop. There are two types of customers in your market, coffee addicts, and casual drinkers. Because coffee addicts buy large amounts of coffee, they are more...
-
2.2 How much of the mass and how much of the volume of an atom are in the nucleus?
-
(AICPAs Role in Standards Setting) One of the major groups involved in the standards-setting process is the American Institute of Certified Public Accountants. Initially it was the primary...
-
What is the effect of a weak euro on European exporters? What is the effect on European consumers? LO.1
-
What is the present worth of a series of equal quarterly payments of $3000 that extends over a period of 8 years if the interest rate is 10% compounded monthly?
-
Scenario 3: Paula is a single taxpayer and loves to go to flea markets, garage sales, and antique shows. Five years ago she purchased a small oil painting at a garage sale for $20. Two months ago she...
-
Which of the following is most likely to be caused by a race condition? A. A thread perpetually denied access to a resource B. A program hanging indefinitely C. An int variable incorrectly reporting...
-
Which ScheduledExecutorService method can result in the same action being executed by two threads at the same time? A. scheduleAtFixedDelay() B. scheduleAtFixedRate() C. scheduleWithFixedDelay() D....
-
Beasley Services Company (BSC) has 50 employees, 28 of whom are assigned to Division A and 22 to Division B. BSC incurred $450,000 of fringe benefits cost during 2018. Required Determine the amount...
-
Sample grade point averages for ten male students and ten female students are listed. Males 2.4 3.7 3.8 3.9 Females 2.8 3.7 2.1 3.9 2.8 2.6 3.6 3.3 4.0 1.9 3.6 4.0 2.0 3.9 3.7 2.3
-
Fill in the columns in the following table. What quantity should a profit-maximizing firm produce? Verify your answer with marginal reasoning. 9 0 1 2 3 st 4 5 6 TFC $5 5 5 5 5 5 5 TVC $0 3 5 9 16 25...
-
Perform the experiments in Problems 48-51, tally your results, and calculate the probabilities (to the nearest hundredth). Flip three coins simultaneously 100 times, and note the results. The...
-
The following information is available for Spring Inc. and Winter Inc. at December 31, 2011: Required a. What is the accounts receivable turnover for each of the companies for 2011? b. What is the...
-
Margin of error = 0.5 g, standard deviation = 8.7 g
-
Imagine that you are president of the HR student association at your school. You want to measure the success of the association during your term. What metrics would you use? What benchmarks would you...
-
In 1995 Miguel purchased a home for $130,000. In 2000 he sold it for $170,000 and immediately purchased another one for $180,000, which he sold in 2007 for $235,000. How much taxable capital gain, if...
-
Explain why we can have different intradomain routing protocols in different ASs, but we need only one interdomain routing protocol in the whole Internet.
-
In Figure 20.24, assume that the intra-AS routing protocol used by AS1 is OSPF, but the one used by AS2 is RIP. Explain how R5 can find how to route a packet to N4. Figure 20.24 A sample internet...
-
Can a router combine the advertisement of a link and a network in a single link-state update?
-
Flexible manufacturing places new demands on the management accounting information system and how performance is evaluated. In response, a company should a. institute practices that reduce switching...
-
Revenue and expense items and components of other comprehensive income can be reported in the statement of shareholders' equity using: U.S. GAAP. IFRS. Both U.S. GAAP and IFRS. Neither U.S. GAAP nor...
-
Kirk and Spock formed the Enterprise Company in 2010 as equal owners. Kirk contributed land held an investment ($50,000 basis; $100,000 FMV), and Spock contributed $100,000 cash. The land was used in...
Study smarter with the SolutionInn App