質問編集履歴

2

問題集の内容であることを追記

2020/04/29 12:18

投稿

kazu0630
kazu0630

スコア26

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
-
13
+ 以下問題集の内容抜粋
14
14
 
15
15
  ```Java
16
16
 

1

コードの修正

2020/04/29 12:18

投稿

kazu0630
kazu0630

スコア26

test CHANGED
File without changes
test CHANGED
@@ -14,85 +14,85 @@
14
14
 
15
15
  ```Java
16
16
 
17
- 1 package deadlock;
17
+ public class Test {
18
18
 
19
- 2
20
19
 
21
- 3 public class Test {
22
20
 
23
- 4
21
+ public static void main(String[] args) {
24
22
 
25
- 5 public static void main(String[] args) {
23
+ // TODO 自動生成されたメソッド・スタブ
26
24
 
27
- 6 CountThread c1 = new CountThread();
28
25
 
29
- 7 CountThread c2 = new CountThread();
30
26
 
31
- 8 c1.setCountThread(c2);
27
+ CountThread c1 = new CountThread();
32
28
 
33
- 9 c2.setCountThread(c1);
29
+ CountThread c2 = new CountThread();
34
30
 
35
- 10 c1.start();
31
+ c1.setCountThread(c2);
36
32
 
37
- 11 c2.start();
33
+ c2.setCountThread(c1);
38
34
 
39
- 12 }
35
+ c1.start();
40
36
 
41
- 13 }
37
+ c2.start();
42
38
 
43
- 14
39
+ }
44
40
 
45
- 15 class CountThread extends Thread {
41
+ }
46
42
 
47
- 16 CountThread c;
48
43
 
49
- 17 int i = 0;
50
44
 
51
- 18
45
+ class CountThread extends Thread {
52
46
 
53
- 19 public void setCountThread(CountThread c) {
47
+ CountThread c;
54
48
 
55
- 20 this.c = c;
49
+ int i = 0;
56
50
 
57
- 21 }
58
51
 
59
- 22
60
52
 
61
- 23 public synchronized void display(CountThread c) {
53
+ public void setCountThread(CountThread c) {
62
54
 
63
- 24 try {
55
+ this.c = c;
64
56
 
65
- 25 Thread.sleep(10);
57
+ }
66
58
 
67
- 26 c.show();
68
59
 
69
- 27 } catch (InterruptedException e) {
70
60
 
71
- 28
61
+ public synchronized void display(CountThread c) {
72
62
 
73
- 29 }
63
+ try {
74
64
 
75
- 30 }
65
+ Thread.sleep(10);
76
66
 
77
- 31
67
+ c.show();
78
68
 
79
- 32 public synchronized void show() {
69
+ } catch (InterruptedException e) {
80
70
 
81
- 33 System.out.println(c.getName());
82
71
 
83
- 34 }
84
72
 
85
- 35
73
+ }
86
74
 
87
- 36 public void run() {
75
+ }
88
76
 
89
- 37 display(c);
90
77
 
91
- 38 }
92
78
 
93
- 39
79
+ public synchronized void show() {
94
80
 
81
+ System.out.println(c.getName());
82
+
95
- 40 }
83
+ }
84
+
85
+
86
+
87
+ public void run() {
88
+
89
+ display(c);
90
+
91
+ }
92
+
93
+
94
+
95
+ }
96
96
 
97
97
 
98
98