public class SleepSort {
public static void main(String[] args) {
int[] arr={2,6,8,1,3,5,4,10,9};
sleepSort(arr);
}
public static void sleepSort(int[] arr){
for (int i = 0; i < arr.length; i++) {
final int num=arr[i];
new Thread(()->{
try {
Thread.sleep(num*arr.length*10);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println(num);
}).start();
}
}
}
结果: