日期:2014-05-20  浏览次数:20576 次

求助 关于线程的问题 大家来看看啊
import java.util.ArrayList;
////
public class Thread_test implements Runnable{
static ArrayList aaa = new ArrayList();
int i1,i2;
static int num;
static Thread tt[] = new Thread[100];;
static Thread_test t1;

public void init(){
for(int i =0; i<1000;i++){
aaa.add(i, i);
}
}

public void run() {

for(int i=i1;i<i2;i++){
System.out.println(i1+" "+aaa.get(i));
}

}

public void Main(){
//Thread ttt = new Thread(t1);
//try {
// ttt.join();
//} catch (InterruptedException e) {
// e.printStackTrace();
//}

init();
for(int i=0;i<100;i++){
i1 = i*10;
i2 = (i+1)*10;
tt[i] = new Thread(this);
tt[i].run();
System.out.println(tt[i].getName()+" start");
}


}

public static void main(String[] args){
t1 = new Thread_test();
t1.Main();

}
}






代码如上,他现在是第一个线程里的东西执行完了才进行下一个线程。我想让线程同时进行,该怎么办啊???

------解决方案--------------------
tt[i].run();
写错了,应该是:
tt[i].start();
------解决方案--------------------
我也新手,刚好看到线程,start() 用于启动线程。run() 包含线程运行时所执行的代码。