-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSynchronize.java
More file actions
42 lines (21 loc) · 886 Bytes
/
TestSynchronize.java
File metadata and controls
42 lines (21 loc) · 886 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
package synchronize;
import java.lang.management.ClassLoadingMXBean;
public class TestSynchronize {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
Counter myCounter = new Counter();
UpdaterThread CounterThread1 = new UpdaterThread(myCounter);
UpdaterThread CounterThread2 = new UpdaterThread(myCounter);
CounterThread1.start();
CounterThread2.start();
try {
CounterThread1.join();
CounterThread2.join();
} catch (Exception e) {
System.out.println("Thread interrupted: " + e.getMessage());
// TODO: handle exception
}
long endTime = System.currentTimeMillis();
System.out.printf("Final count is %d and time taken is %d ms \n", myCounter.getCount(), endTime - startTime);
}
}