What is the output of the following application? A. Hare won the race! is printed first. B.
Question:
What is the output of the following application?
A. Hare won the race! is printed first.
B. Tortoise won the race! is printed first.
C. The code does not compile.
D. The code hangs indefinitely at runtime.
E. The code throws an exception at runtime.
F. The output cannot be determined ahead of time.
Transcribed Image Text:
import java.util. *; import java.util.concurrent.*; public class Race { Executor Service service = Executors.newFixedThreadPool (8); public static int sleep() { try {Thread.sleep (1000); } catch (Exception e) {} return 1; } public void hare() { try { System.out.println ("Hare won the race!"); } catch (Exception e) {e.printStackTrace (); } } public void tortoise() { try { Callable c = () -> sleep(); final var r= List.of (c,c,c); var results = service.invokeAll(r); Callable c = () -> sleep(); final var r List.of (c,c,c); Integer result = service.invokeAny (r); System.out.println("Tortoise won the race!"); } catch (Exception e) {e.printStackTrace();} } } public static void main(String[] p) throws Exception { var race = new Race(); race.service.execute(() -> race.hare()); race.service.execute(() -> race.tortoise()); }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (QA)
The provided image shows a Java application ...View the full answer
Answered By
Jayshree Rathi
Hello Students!
This is Jayshree Rathi. I work on a number of renowned student-centric channels such as Chegg, coursehero, as a certified private tutor.
If you are looking for relevant and original content to complete your assignments, essays, and homework, then contact me and within the promised time, I will deliver you your personalized academic work and help you score the best.
4.80+
1+ Reviews
10+ 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
-
Student work here ASSETS Current assets Cash and cash equivalents Trade and other receivables Inventories Other Current Assets Total current assets Non-current assets Available for sale investments...
-
The following program simulates flipping a coin an even number of times. Assuming five seconds is enough time for all of the tasks to finish, what is the output of the following application? A. false...
-
Describe, in detail, how the heapsort algorithm works. [10 marks] Show that the worst-case cost of heapsort is O(n log n). [6 marks] Would it be possible to implement a variant of heapsort based on a...
-
Calculate the investment return, BAR, and ALPHA of the following investment, all over one year. Market return .12 or 12% investment in Tesla stock, $15000 , then sold at end of year for $32000, bet...
-
Why was Turkey an important ally to Germany in World War II?
-
If each systolic reading is exactly twice the diastolic reading, what is the value of the linear correlation coefficient r?
-
If you wanted to expand your business to include international customers and vendors, what factors would influence your decision?
-
The athletic boosters club for Beaconville has planned a 2-day fund-raising drive to purchase uniforms for all the local high schools and to improve facilities. Donations will be solicited during the...
-
The atomic number of element M, N, R, and T are 1, 8, 12 and 14 respectively. The element which can form ions by either losing or gaining electron(s) is M 11. A. B. N C R D. T 12. The atomic number...
-
Which of the following concurrent collections is sorted? (Choose two.) A. ConcurrentSkipList B. ConcurrentSkipListSet C. CopyOnWriteArrayList D. ConcurrentSkipListMap E. ConcurrentLinkedQueue F....
-
The following diagrams represent the order of read/write operations of two threads sharing a common variable. Each thread first reads the value of the variable from memory and then writes a new value...
-
You are given the representation: Where the equality holds given the sequence of information sets {I t . The underlying process X t is known to follow the SDE: dX t = ?dt + ?dW t Determine the g(-)...
-
Farell is a member of Sierra Vista LLC. Although Sierra Vista is involved in a number of different business ventures, it is not currently involved in real estate either as an investor or as a...
-
Given the following tax structure: Taxpayer Mae Pedro Salary $ 39,000 $ 47,000 Total tax $ 1,794 ??? Required: a. What is the minimum tax that Pedro should pay to make the tax structure vertically...
-
A researcher is investigating the impact of a firm's capital intensity on its labour productivity using data for the year 2014 for a sample of manufacturing firms from Germany, France, Sweden, Italy...
-
Given the nature of corporate financing and investment decisions, that focus on long-term operations is appropriate. In periods of rapid change where long-term outlooks are uncertain or in flux, a...
-
Gibson Corporation paid one of its sales representatives $6,500 during the month of March. The rep is paid a base salary plus $12 per unit of product sold. During March, the rep sold 150 units....
-
Company A had sales for the year totaling $480,000. The net property, plant, and equipment balance at the beginning of the year was $160,000; the ending balance was $200,000. Compute the fixed asset...
-
Maria Castigliani is head of the purchasing department of Ambrosiana Merceti, a medium-sized construction company. One morning she walked into the office and said, The main problem in this office is...
-
Assume that the network in Figure 20.34 (previous problem) uses distancevector routing with the forwarding table as shown for each node. If each node periodically announces their vectors to the...
-
Router A sends two RIP messages to two immediate neighboring routers, B and C. Do the two datagrams carrying the messages have the same source IP addresses? Do the two datagrams have the same...
-
Assume that the network in Figure 20.34 uses distance-vector routing with the forwarding table as shown for each node. Figure 20.34 If each node periodically announces their vectors to the neighbor...
-
1. Given the function f(x) = 2x 2 - 3x - 5, determine the following: a) x-intercepts b) y-intercept c) Does the graph have a maximum or a minimum value? What is the value? d) Vertex e) Equation of...
-
1. Using the data below, complete the percentage column in the frequency table. You are given the total for each category; you need to calculate the percentages. After you have calculated the...
-
is it possible for latency time to really be zero? explain you chose your answer ?
Study smarter with the SolutionInn App