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

Assuming 10 seconds is enough time for all of the tasks to finish, what is the output of the following application? 

import java.util.concurrent.*; public class Bank { static int cookies = 0; public

A. 0

B. 125

C. -125

D. The code does not compile.

E. The result is unknown until runtime.

F. An exception is thrown.

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 bank.deposit (5)); teller.submit(() -> bank.withdrawal (5)); } teller.shutdown(); teller.awaitTermination (10, TimeUnit. SECONDS); System.out.print(bank.cookies); } }

Step by Step Solution

3.41 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The code provided creates a simple threadsafe banking application using a Bank class with two synchr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Oracle Questions!