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