Assuming 10 seconds is enough time for all of the tasks to finish, what is the output
Question:
Assuming 10 seconds is enough time for all of the tasks to finish, what is the output of the following application?
A. 0
B. 125
C. -125
D. The code does not compile.
E. The result is unknown until runtime.
F. An exception is thrown.
Transcribed Image Text:
import java.util.concurrent.*; public class Bank { static int cookies = 0; public synchronized void deposit(int amount) { cookies += amount; } public static synchronized void withdrawal (int amount) { cookies amount; } public static void main(String[] amount) throws Exception { var teller= Executors.newScheduled ThreadPool (50); Bank bank = new Bank (); for (int i-0; i <25; i++) { teller.submit(() -> bank.deposit (5)); teller.submit(() -> bank.withdrawal (5)); } teller.shutdown(); teller.awaitTermination (10, TimeUnit. SECONDS); System.out.print(bank.cookies); } }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 50% (2 reviews)
The code provided creates a simple threadsafe banking application using a Bank class with two synchr...View the full answer
Answered By
Nyron Beeput
I am an active educator and professional tutor with substantial experience in Biology and General Science. The past two years I have been tutoring online intensively with high school and college students. I have been teaching for four years and this experience has helped me to hone skills such as patience, dedication and flexibility. I work at the pace of my students and ensure that they understand.
My method of using real life examples that my students can relate to has helped them grasp concepts more readily. I also help students learn how to apply their knowledge and they appreciate that very much.
4.00+
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
-
Assuming 10 seconds is enough time for all of the tasks to finish, what statements about the following program are correct? (Choose two.) A. The code does not compile. B. The incrementBy10() method...
-
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...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
To some U.S. manufacturers and labor unions, a cheap yuan value gives China's advantage in the global economy. bankers exports importers subsidies an unfair
-
The process described in Problem 2.11 is a nuclear reaction because it involves changes in the nucleus. Is it nuclear fusion or nuclear fission?
-
Jason Furman served as the chairman of the White House Council of Economic Advisers under President Obama. In an opinion column in the Wall Street Journal discussing President Trumps tax reform...
-
a deontological philosopher, stated in An Exposition of The Fundamental Principles of Jurisprudence as the Science of Right that Judicial Punishment can never be administered merely as a means for...
-
Create a Sensitivity Report for Electro-Polys make vs. buy problem in section 3.8 of Chapter 3 and answer the following questions. a. Is the solution degenerate? b. How much can the cost of making...
-
16. A signal containing multiple frequencies is shown in figure A. It is passed through 2 different filters and then outputs are shown in figure B & C. M (A) S (B) sha (C) (a) B corresponds to low...
-
What is the output of the following application? A. true B. false C. The code does not compile. D. The result is unknown until runtime. E. An exception is thrown. F. None of the above. import...
-
Which ExecutorService method guarantees all running tasks are stopped in an orderly fashion? A. shutdown() B. shutdownNow() C. halt() D. shutdownAndTerminate() E. None of the above.
-
(a) In Figure 10.2, what is the ball's velocity the instant before it is released? (b) Is the ball's speed in the reference frame of the cart greater than, equal to, or smaller than its speed in the...
-
Evaluate the past financial performance of Nike. Determine Nike future financial performance.
-
Do you think AUD will be appreciating or depreciating GBP in the next 3-6 months and if so why?
-
Why should you try to minimize spending and maximize saving? Explain at least one paragraph.
-
Discusses considerations for forecasting volumes for the budget. What factors are impacting volumes at your institution? Explain.
-
A conservative investor has a well-diversified portfolio but is still concerned about two things. First, he is concerned about the downside risk and secondly, he is concerned whether he is earning a...
-
In 2011, the Slidell Corporation incurred research and development costs as follows: Materials and equipment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . $160,000 Personnel . . . . . ....
-
In the series connection below, what are the respective power consumptions of R, R2, and R3? R R www 4 V=6V P1-3 W; P2=3W; and P3= 3 W OP10.5 W; P2-1 W; and P3= 1.5 W P1=1.5 W; P2=1 W; and P3= 0.5 W...
-
Mention the three auxiliary protocols at the network layer of the TCP/IP suite that are designed to help the IPv4 protocol.
-
In Figure 19.4, show how the sum, wrapped sum, and checksum can be calculated when each word (16 bits) is created instead of waiting for the whole packet to be created. Figure 19.4 Example of...
-
In an IPv4 datagram, the value of the header-length (HLEN) field is (6) 16 . How many bytes of options have been added to the packet?
-
Create the database schemer. Create the tables shown in your ERD from AT1, along with the keys, constraints and datatypes. Make sure that you include a pair of tables with a primary and foreign key...
-
At the bottom of the Excel workbook, you will see a sheet titled Physical Ability , which contains the observed data for a physical ability test used for selection. You will be comparing the pass and...
-
Michael contracted with William to mow William's lawn for 2 0 weeks at $ 5 0 per week. Later, without terminating the first contract, the parties modify their agreement as follows: Michael agrees to...
Study smarter with the SolutionInn App