1
2
3
4
5
6
7public
8class SyncTest2 {
9
10 public static
11 Resource buffer = new Resource();
12
13
14
15 public static
16 void main(String[] argv) {
17 Thread [] threads = {
18 new Producer(buffer),
19 new Producer(buffer),
20 new Consumer(buffer),
21 new Consumer(buffer)
22 };
23
24 String [] names = {
25 "producer1",
26 "producer2",
27 "consumer1",
28 "consumer2"
29 };
30
31 for (int i = 0;
32 i < threads.length;
33 ++i) {
34 threads[i].setName(names[i]);
35 threads[i].start();
36 }
37 }
38}