-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadDemo13.java
More file actions
45 lines (36 loc) · 873 Bytes
/
Copy pathThreadDemo13.java
File metadata and controls
45 lines (36 loc) · 873 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
package secondPart;
import secondPart.Thread13Test.Inner;
public class ThreadDemo13 {
public static void main(String[] args) {
final Inner inner = new Inner();
Thread a = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
inner.play(1, "AA");
}
});
Thread b = new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
inner.play2(1, "BB");
}
});
a.start();
b.start();
}
}
class Thread13Test {
static class Inner {
public synchronized void play(int a, String name) {
for (int i = 0; i < 10; i++) {
System.out.println(name + " == " + a++);
}
}
public synchronized void play2(int a, String name) {
for (int i = 0; i < 10; i++) {
System.out.println(name + " == " + a++);
}
}
}
}