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% (QA)
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?
-
Given that the P-value for the hypothesis test is 0.971, what do you conclude? The table lists frequencies for randomly selected nonfatal occupation injuries arranged according to day of the week....
-
Acclaimed screenwriter and director Woody Allen directed Midnight in Paris, a 2011 film that is set in Paris, France. In the movie, one of the characters states, The past is not dead. Actually, its...
-
The following is an excerpt from a conversation between the store manager of Yoder Brothers Grocery Stores, Lori Colburn, and Terry Whipple, president of Yoder Brothers Grocery Stores. Terry: Lori,...
-
19 20 Assertion A compass needle is placed near a current carrying wire. The deflection of the compass needle decreases when the magnitude of the current in the wire is increased. Reason The strength...
-
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....
-
Following is information on the price per share and the dividend for a sample of 30 companies. a. Calculate the regression equation that predicts price per share based on the annual dividend. b. Test...
-
A credit card account with an APR of 16.9% had an average daily balance of $360.4 over billing cycle of 30 days. What would the monthly finance charge be for this account?
-
You have saved $500 to buy an electric scooter that costs $1800. You plan to borrow the rest of the purchase price from the bank. The bank is offering a 3 year loan at 4% APR with monthly payments....
-
A sleep study administered to U.S. adults showed that the amount of sleep (in hours) they get in a 24-hour period is normally distributed with a mean of 6.5 hours and a standard deviation of 1.25...
-
In the year 2009, Anytown, Colorado has a population of 30,000. Use the model p = 30e 0.0198026273t to predict the population of Anytown in the year 2015. Include units of measurement, i.e. people or...
-
A company in the energy industry is affected by a new technology that should open up new sources of revenue. But this new technology will also make the energy company riskier in the future. What is...
-
Custom Industries purchases new specialized manufacturing equipment on July 1, 2011. The equipment cash price is $96,000. Custom signs a deferred payment contract that provides for a down payment of...
-
According to a New York Times columnist, The estate tax affects a surprisingly small number of people. In 2003, . . . just 1.25 percent of all deaths resulted in taxable estates, with most of them...
-
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?
-
compiler design 10 marks 1. Construct an NFA NFA for the regular expression (bla) * b|al and Convert the an equivalent NFA to DFA
-
Canadian Pacific Railway (known as "CP"), with headquarters in Calgary, Alberta, owns approximately 20,100 kilometers of track in seven provinces of Canada and into the United States. Review CP's...
-
Divide and simplify, if possible. 2x+6 (x+3) 3x-15 (x-5)
Study smarter with the SolutionInn App