/*
* 睡排序 * 利用线程休眠(苏醒时间)将数排序 */public class Demo { public static void main(String[] args) { int[] sortNum = {-1,0,1,4,7,3,8,9,2,6,5,555}; SortThread[] sortThreads = new SortThread[sortNum.length]; for (int i = 0; i < sortThreads.length; i++) { //接收数字充当休眠时间 sortThreads[i] = new SortThread(sortNum[i]); } for (int i = 0; i < sortThreads.length; i++) { sortThreads[i].start(); } }}
class SortThread extends Thread{
int num = 0; public SortThread(int num){ this.num = num; } public void run(){ try { sleep(num); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(num); } }