-1

8 行目または 16 行目でどのようにデッドロックが発生しますか?

 1. public class DeadlockRisk {
 2.   private static class Resource {
 3.     public int value;
 4.   }
 5.   private Resource resourceA = new Resource();
 6.   private Resource resourceB = new Resource();
 7.   public int read() {
 8.     synchronized(resourceA) { 
 9.       synchronized(resourceB) {
10.         return resourceB.value + resourceA.value;
11.       }
12.     }
13.   }
14
15.   public void write(int a, int b) {
16.     synchronized(resourceB) { 
17.       synchronized(resourceA) {
18.         resourceA.value = a;
19.         resourceB.value = b;
20.       }
21.     }
22.   }
23. }
4

2 に答える 2