2,Java并发编程:如何创建线程
发布网友
发布时间:2022-05-26 13:54
我来回答
共1个回答
热心网友
时间:2023-10-20 15:04
public static void main(String[] args) {
for(Thread t:getThreads()){
t.start();
}
}
public static Thread[] getThreads(){
Thread[] thread = new Thread[10];
for(int i=0;i<10;i++){
final Integer num = new Integer(i);
thread[i] = new Thread(new Runnable(){
public void run() {
int j=5;
while(j-->0){
System.out.println("this is thread"+num);
}
}
});
}
return thread;
}