java 并发实现原理: 是否可以利用多线程,实现10个并发执行 请给个例子(java代码),非常感谢!!!!

如题所述

第1个回答  推荐于2017-10-06
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;
}本回答被提问者采纳
第2个回答  2011-08-08
可以的,例子我就不写了,不过推荐你看看马士兵的教程,很权威
相似回答