-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest01.java
More file actions
41 lines (28 loc) · 817 Bytes
/
Test01.java
File metadata and controls
41 lines (28 loc) · 817 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
package a001_nano_sleep;
public class Test01 {
public static void main(String[] args) throws InterruptedException {
final int[] nano_sleep = { 999999, 99999, 9999, 999, 99, 9 };
for (int i : nano_sleep) {
System.out.println("=========>" + i);
a(i);
b(i);
System.out.println("");
}
}
static void a(final int nano_sleep) throws InterruptedException {
final long l1 = System.nanoTime();
Thread.sleep(0, nano_sleep);
final long l2 = System.nanoTime();
System.out.printf("%d %d %07d%n", l1, l2, l2 - l1);
}
static void b(final int nano_sleep) {
final long l1 = System.nanoTime();
{
long start = System.nanoTime();
while (start + nano_sleep >= System.nanoTime())
;
}
final long l2 = System.nanoTime();
System.out.printf("%d %d %07d%n", l1, l2, l2 - l1);
}
}