Click the Exhibit button. 10. public class Transfers { 11. public static void main(String[] args) throws Exception { 12. Record r1 = new Record(); 13. Record r2 = new Record(); 14. doTransfer(r1, r2, 5); 15. doTransfer(r2, r1, 2); 16. doTransfer(r1, r2, 1); 17. // print the result 18. System.out.println(”rl = “ + r1.get() +“, r2=” + r2.get()); 19. } 20. private static void doTransfer( 21. final Record a, final Record b, final int amount) { 22. Thread t = new Thread() { 23. public void run() { 24. new Clerk().transfer(a, b, amount); 25. } 26. }; 27. t.start(); 28. } 29. } 30. class Clerk { 31. public synchronized void transfer(Record a, Record b, int amount){ 32. synchronized (a) { 33. synchronized (b) { 34. a.add(-amount); 35. b.add(amount); 36. } 37. } 38. } 39. } 40. class Record { 41.int num=10; 42. public int get() { return num; } 43. public void add(int n) { num = num + n; } 44. } If Transfers.main() is run, which three are true? (Choose three.)
Reveal answer
Fill a bubble to check yourself
Keep practicing — related questions
- Click the Exhibit button. 1. import java.util.*; 2. 3. public class NameList { 4. private List names = new ...
- Click the Exhibit button. 1. public class A { 2. public void method1() { 3. B b=new B(); 4. b.method2(); 5....
- What will be the output of the program? class s implements Runnable { int x, y; public void run() { for(int...
- Click the Exhibit button. 1. public class A { 2. public String doit(int x, int y) { 3. return “a”; 4. } 5. ...
- What is the output? class sample4 extends Thread { public static void main(String[] args) { new sample4().s...
- Click the Exhibit button. 1. public class A { 2. 3. private int counter = 0; 4. 5. public static int getIns...
- Given: 1. public class Threads4 { 2. public static void main (String[] args) { 3. new Threads4().go(); 4. }...
- What will be the output of the program? public class SyncTest { public static void main (String [] args) { ...