休眠排序
根据线程的休眠来排序
class SortThread extends Thread{
private int value;
public SortThread(int value) {
this.value = value;
}
@Override
public void run() {
try {
Thread.sleep(value);
System.out.println(value);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class Sort6_ThreadSleepSort {
public static void main(String[] args) {
int[] arr = {10, 100, 30, 50, 2, 60};
for (int i = 0; i < arr.length; i++) {
new SortThread(arr[i]).start();
}
}
}
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
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
编辑 (opens new window)
上次更新: 2021/06/27, 10:49:09