public static void main(String[] args) {
int[] arr = {1,4,7,3,8,9,2,6,5};
//創建指定長度的線程數組
SThread[] threads = new SThread[arr.length];
//指定每個線程數組的值
for (int i = 0; i < threads.length; i++) {
threads[i] = new SThread(arr[i]);
}
//開啓每個線程
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
}
static class SThread extends Thread{
int s = 0;
public SThread(int s){
this.s = s;
}
public void run(){
try {
sleep(s); //睡眠指定的時間
} catch (InterruptedException e) {
e.printStackTrace();
}
//輸出該數
System.out.println(s);
}
}