-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCuncurrencyTest.java
More file actions
45 lines (41 loc) · 1.11 KB
/
CuncurrencyTest.java
File metadata and controls
45 lines (41 loc) · 1.11 KB
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
/**
* @author hyperglory
* @date 2017/1/11 16:06
*/
public class CuncurrencyTest {
private static final long COUNT = 100000001l;
public static void main(String[] args) throws InterruptedException {
concurrency();
serial();
}
public static void concurrency() throws InterruptedException {
long start = System.currentTimeMillis();
Thread thread = new Thread(() -> {
int a = 0;
for (long i = 0; i < COUNT; i++) {
a += 5;
}
});
thread.start();
int b = 0;
for (long i = 0; i < COUNT; i++) {
b--;
}
long stop = System.currentTimeMillis();
thread.join();
System.out.println(stop - start);
}
public static void serial() {
long start = System.currentTimeMillis();
int a = 0;
for (long i = 0; i < COUNT; i++) {
a += 5;
}
int b = 0;
for (long i = 0; i < COUNT; i++) {
b--;
}
long stop = System.currentTimeMillis();
System.out.println(stop - start);
}
}