forked from striner/javaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadSleepUtilTest.java
More file actions
57 lines (44 loc) · 1.14 KB
/
Copy pathThreadSleepUtilTest.java
File metadata and controls
57 lines (44 loc) · 1.14 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
46
47
48
49
50
51
52
53
54
55
56
57
package utils;
import common.utils.ThreadSleepUtil;
import org.junit.Test;
public class ThreadSleepUtilTest {
@Test
public void test1() {
for (int i = 20; i < 80; i++) {
System.out.println("i = " + i);
ThreadSleepUtil.sleep(500L);
}
}
@Test
public void sleepSort() {
int[] nums = {6, 9, 4, 15, 1, 5, 2, 9, 9, 22, 42};
Sleeper.idx = 0;
Sleeper.output = new int[nums.length];
for(int i = 0; i < nums.length; i++) {
new Sleeper(nums[i]).start();
}
ThreadSleepUtil.sleep(100);
for (int i = 0; i < nums.length; i++) {
nums[i] = Sleeper.output[i];
}
for (int num : nums) {
System.out.print(num + " ");
}
}
}
class Sleeper extends Thread{
public static int[] output;
public static int idx;
private int sleep_time;
public Sleeper(){
this.sleep_time=0;
}
public Sleeper(int sleep_time){
this.sleep_time=sleep_time;
}
@Override
public void run(){
ThreadSleepUtil.sleep(sleep_time);
output[idx++]=this.sleep_time;
}
}