-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHogeThread.java
More file actions
45 lines (34 loc) · 928 Bytes
/
HogeThread.java
File metadata and controls
45 lines (34 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class HogeThread extends Thread {
private static int hoge = 0;
private static synchronized int getHoge(){
return hoge;
}
private static volatile int fuga = 0;
private static synchronized int getFuga(){
return fuga;
}
public void start() {
System.out.println("Runnable");
super.start();
}
public void run() {
System.out.println("Running");
for (int i = 0; i < 5; i++) {
System.out.println(getName() + "Count:" + i);
hoge++;
fuga++;
System.out.println(getName() + "hoge:" + hoge);
System.out.println(getName() + "fuga:" + fuga);
System.out.println(getName() + "getHoge:" + getHoge());
System.out.println(getName() + "getFuga:" + getFuga());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Interrupted");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("Dead");
}
}