码迷,mamicode.com
首页 > 编程语言 > 详细

睡排序--利用线程sleep的时间排序

时间:2018-06-12 20:59:59      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:int   exception   thread   extends   rup   xtend   public   线程   his   

/*
* 睡排序
* 利用线程休眠(苏醒时间)将数排序
*/
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);
}
}

睡排序--利用线程sleep的时间排序

标签:int   exception   thread   extends   rup   xtend   public   线程   his   

原文地址:https://www.cnblogs.com/zxwm/p/9174793.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!