非原创,大佬地址:
沙雕代码之【睡眠排序】深度讲解-哔哩哔哩】 https://b23.tv/wcRUMuW
/**
* @author sunyuan
* @date 2022/4/26 22:34
*/
public class Solution {
public static void main(String[] args) {
int[] nums = {2,11,5,8,6,100,1};
sleepSort(nums);
}
/**
* 多线程睡眠排序大发
*
* @param nums
*/
public static void sleepSort(int[] nums) {
for (int i = 0; i < nums.length; i++) {
final int NUM = nums[i];
new Thread(() -> {
try {
Thread.sleep(NUM);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(NUM);
}).start();
}
}
}